2023-03-31 11:49:03 +02:00
|
|
|
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"`
|
2023-03-31 11:49:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|