2023-07-10 14:45:52 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2023-08-27 21:30:19 +02:00
|
|
|
"fmt"
|
2023-07-10 14:45:52 +02:00
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/kelseyhightower/envconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2023-08-27 21:30:19 +02:00
|
|
|
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"`
|
2023-07-10 14:45:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(envFile string) *Config {
|
|
|
|
if envFile != "" {
|
2023-08-27 21:30:19 +02:00
|
|
|
err := godotenv.Load(envFile)
|
2023-07-10 14:45:52 +02:00
|
|
|
if err != nil {
|
2023-08-27 21:30:19 +02:00
|
|
|
panic(fmt.Errorf("godotenv.Load: %w", err))
|
2023-07-10 14:45:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := &Config{}
|
|
|
|
err := envconfig.Process("", cfg)
|
|
|
|
if err != nil {
|
2023-08-27 21:30:19 +02:00
|
|
|
panic(fmt.Errorf("envconfig.Process: %w", err))
|
2023-07-10 14:45:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return cfg
|
|
|
|
}
|