41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
|
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 {
|
||
|
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"`
|
||
|
EmployeeWorkInformationCollection string `required:"true" split_words:"true"`
|
||
|
EmployeeIdList []string `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
|
||
|
}
|