backblaze-backup/kit/config/config.go

32 lines
588 B
Go
Raw Normal View History

2023-07-10 14:45:52 +02:00
package config
import (
"log"
"gitea.urkob.com/urko/backblaze-backup/kit"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
type Config struct {
BbId string `required:"true" split_words:"true"`
BbKey string `required:"false" split_words:"true"`
}
func NewConfig(envFile string) *Config {
if envFile != "" {
err := godotenv.Load(kit.RootDir() + "/" + envFile)
if err != nil {
log.Fatalln("godotenv.Load:", err)
}
}
cfg := &Config{}
err := envconfig.Process("", cfg)
if err != nil {
log.Fatalf("envconfig.Process: %s\n", err)
}
return cfg
}