mirror of
https://github.com/ordinary-dev/phoenix
synced 2024-09-20 03:40:29 +05:00
46 lines
808 B
Go
46 lines
808 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"github.com/joho/godotenv"
|
||
|
"github.com/kelseyhightower/envconfig"
|
||
|
"github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
type Config struct {
|
||
|
SecretKey string `required:"true"`
|
||
|
DBPath string `required:"true"`
|
||
|
LogLevel string `default:"warning"`
|
||
|
}
|
||
|
|
||
|
func GetConfig() (*Config, error) {
|
||
|
err := godotenv.Load()
|
||
|
if err != nil {
|
||
|
logrus.Infof("Config: %v", err)
|
||
|
}
|
||
|
|
||
|
var cfg Config
|
||
|
err = envconfig.Process("p", &cfg)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &cfg, nil
|
||
|
}
|
||
|
|
||
|
func (cfg *Config) GetLogLevel() logrus.Level {
|
||
|
switch cfg.LogLevel {
|
||
|
case "debug":
|
||
|
return logrus.DebugLevel
|
||
|
case "info":
|
||
|
return logrus.InfoLevel
|
||
|
case "warning":
|
||
|
return logrus.WarnLevel
|
||
|
case "error":
|
||
|
return logrus.ErrorLevel
|
||
|
case "fatal":
|
||
|
return logrus.FatalLevel
|
||
|
default:
|
||
|
return logrus.WarnLevel
|
||
|
}
|
||
|
}
|