package config import ( "fmt" "github.com/caarlos0/env" "strings" ) type Config struct { E621APIKey string `env:"E621_API_KEY,required"` E621Username string `env:"E621_USERNAME,required"` DBType string `env:"DB_TYPE,required"` DBEndpoint string `env:"DB_URL,required"` DBUsername string `env:"DB_USERNAME,required"` DBPassword string `env:"DB_PASSWORD,required"` LogLevel string `env:"LOG_LEVEL" envDefault:"INFO"` LogFormat string `env:"LOG_FORMAT" envDefault:"PLAIN"` Neo4jDebug bool `env:"NEO4J_DEBUG" envDefault:"FALSE"` } // LoadConfig loads the configuration from environment variables func LoadConfig() (*Config, error) { config := &Config{} if err := env.Parse(config); err != nil { return nil, fmt.Errorf("config: error parsing configuration: %w", err) } logLevel := strings.ToUpper(config.LogLevel) logFormat := strings.ToUpper(config.LogFormat) if logLevel != "FATAL" && logLevel != "ERROR" && logLevel != "WARN" && logLevel != "INFO" && logLevel != "DEBUG" && logLevel != "TRACE" { return nil, fmt.Errorf("config: valid levels for erros are: FATAL, ERROR, WARN, INFO, DEBUG, TRACE") } if logFormat != "PLAIN" && logFormat != "JSON" { return nil, fmt.Errorf("config: valit formatters are: PLAIN, JSON") } return config, nil }