package configuration import ( "fmt" "log/slog" "os" "gopkg.in/yaml.v2" ) const ( AllDomainsApiEndpoint = "/api/v1/get/domain/all" AllAliasesApiEndpoint = "/api/v1/get/alias/all" AliasAddApiEndpoint = "/api/v1/add/alias" ) var ( ConfigFile string DryRun bool Quiet bool ) type Config struct { ApiEndpoint string `yaml:"api_endpoint"` ApiKey string `yaml:"api_key"` AdminEmail string `yaml:"admin_email"` MailPrefixes []string `yaml:"mail_prefixes"` } func (c Config) LoadFromDisk() error { if ConfigFile == "" { slog.Debug("no config file found, looking in working dir") wd, err := os.Getwd() if err != nil { return fmt.Errorf("failed to get current working directory: %w", err) } ConfigFile = wd + "/config.yaml" } slog.Debug("looking for config file", "path", ConfigFile) data, err := os.ReadFile(ConfigFile) if err != nil { return fmt.Errorf("failed to read config file: %w", err) } err = yaml.Unmarshal(data, &c) if err != nil { return fmt.Errorf("failed to unmarshal config file: %w", err) } slog.Debug("successfully read config file", "path", ConfigFile) return nil }