ess-etl-go/config/config.go

45 lines
1.3 KiB
Go
Raw Normal View History

package config
import (
"log"
root_dir "gitea.urkob.com/urko/go-root-dir"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
func RootDir() string {
return root_dir.RootDir("ess-etl-go")
}
type Config struct {
2023-04-24 12:03:15 +02:00
ApiPort string `required:"true" split_words:"true"`
AmsApi string `required:"true" split_words:"true"`
AmsApiKey string `required:"true" split_words:"true"`
DbAddress string `required:"true" split_words:"true"`
DbName string `required:"true" split_words:"true"`
WorkInformationCollection string `required:"true" split_words:"true"`
EmployeeIdList []string `required:"true" split_words:"true"`
TestGoHost string `required:"true" split_words:"true"`
TestGoEmployee string `required:"true" split_words:"true"`
TestNestHost string `required:"true" split_words:"true"`
TestNestEmployee int `required:"true" split_words:"true"`
}
func NewConfig(envFile string) *Config {
if envFile != "" {
err := godotenv.Load(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
}