package config import ( "fmt" "github.com/joho/godotenv" "github.com/kelseyhightower/envconfig" ) type Config struct { BbId string `required:"true" split_words:"true"` BbKey string `required:"true" split_words:"true"` LogLevel uint32 `required:"false" split_words:"true" default:"4"` // Mail vars MailTo string `required:"true" split_words:"true"` MailHost string `required:"true" split_words:"true"` MailPort string `required:"true" split_words:"true"` MailUser string `required:"true" split_words:"true"` MailPassword string `required:"true" split_words:"true"` } func NewConfig(envFile string) *Config { if envFile != "" { err := godotenv.Load(envFile) if err != nil { panic(fmt.Errorf("godotenv.Load: %w", err)) } } cfg := &Config{} err := envconfig.Process("", cfg) if err != nil { panic(fmt.Errorf("envconfig.Process: %w", err)) } return cfg }