32 lines
588 B
Go
32 lines
588 B
Go
|
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
|
||
|
}
|