albatros/pkg/config.go

41 lines
1.4 KiB
Go
Raw Normal View History

2023-04-17 09:25:26 +00:00
package pkg
import (
2023-05-03 08:52:34 +00:00
"fmt"
"github.com/caarlos0/env/v7"
"log"
2023-04-17 09:25:26 +00:00
)
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
}