package configuration import ( "fmt" "os" "github.com/goccy/go-yaml" "github.com/sirupsen/logrus" ) type Config struct { Deconnect Deconnect `yaml:"deconnect"` Upstream Upstream `yaml:"upstream"` } type Deconnect struct { LogLevel logrus.Level `yaml:"log_level"` Host string `yaml:"host"` Port string `yaml:"port"` } type Upstream struct { URL string `yaml:"url"` InsecureTLS bool `yaml:"insecure_tls,omitempty"` } func New() (*Config, error) { deconnectCfgPath := "/etc/deconnect.yaml" if customPath, ok := os.LookupEnv("DECONNECT_CONFIG"); ok { deconnectCfgPath = customPath } rawConfig, err := os.ReadFile(deconnectCfgPath) if err != nil { return nil, fmt.Errorf("%w: %w (%w)", ErrConfiguration, ErrCantReadConfigFile, err) } config := new(Config) err = yaml.Unmarshal(rawConfig, config) if err != nil { return nil, fmt.Errorf("%w: %w (%w)", ErrConfiguration, ErrCantParseConfigFile, err) } return config, nil }