package pkg import ( "log" "fmt" "github.com/caarlos0/env/v7" ) type Config struct { AlbatrosURL string `env:"ALBATROS_URL,required"` NomadAddr string `env:"NOMAD_ADDR"` NomadClientCert string `env:"NOMAD_CLIENT_CERT"` NomadClientKey string `env:"NOMAD_CLIENT_KEY"` NomadCACert string `env:"NOMAD_CACERT"` ConsulAddr string `env:"CONSUL_HTTP_ADDR"` ConsulClientCert string `env:"CONSUL_CLIENT_CERT"` ConsulClientKey string `env:"CONSUL_CLIENT_KEY"` ConsulCACert string `env:"CONSUL_CACERT"` } func BuildConfig() Config { GlobalConfig := Config{} if err := env.Parse(&GlobalConfig); err != nil { log.Fatal(fmt.Sprintf("unable to parse config, error: %+v\n", err)) } log.Printf("Albatros public URL: %s\n", GlobalConfig.AlbatrosURL) if GlobalConfig.NomadAddr != "" { isTLS := GlobalConfig.NomadClientCert != "" && GlobalConfig.NomadClientKey != "" && GlobalConfig.NomadCACert != "" log.Printf("Nomad URL: %s, TLS: %t\n", GlobalConfig.NomadAddr, isTLS) } else { log.Println("Use Nomad default configuration") } if GlobalConfig.ConsulAddr != "" { isTLS := GlobalConfig.ConsulClientCert != "" && GlobalConfig.ConsulClientKey != "" && GlobalConfig.ConsulCACert != "" log.Printf("Consul URL: %s, TLS: %t\n", GlobalConfig.ConsulAddr, isTLS) } else { log.Println("Use Consul default configuration") } return GlobalConfig }