backblaze-backup/kit/config/config.go

39 lines
969 B
Go
Raw Normal View History

2023-07-10 14:45:52 +02:00
package config
import (
"fmt"
2023-07-10 14:45:52 +02:00
"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"`
2023-08-28 08:51:02 +02:00
MailFrom 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 != "" {
err := godotenv.Load(envFile)
2023-07-10 14:45:52 +02:00
if err != nil {
panic(fmt.Errorf("godotenv.Load: %w", err))
2023-07-10 14:45:52 +02:00
}
}
cfg := &Config{}
err := envconfig.Process("", cfg)
if err != nil {
panic(fmt.Errorf("envconfig.Process: %w", err))
2023-07-10 14:45:52 +02:00
}
return cfg
}