package utils import ( "fmt" "github.com/caarlos0/env" ) type Config struct { E621APIKey string `env:"e621_API_KEY"` E621Username string `env:"e621_USERNAME"` Neo4jURL string `env:"NEO4J_URL"` Neo4jUsername string `env:"NEO4J_USERNAME"` Neo4jPassword string `env:"NEO4J_PASSWORD"` } // LoadConfig loads the configuration from environment variables func LoadConfig() (*Config, error) { config := &Config{} if err := env.Parse(config); err != nil { return nil, fmt.Errorf("error parsing configuration: %w", err) } if err := ValidateConfig(config); err != nil { return nil, fmt.Errorf("configuration validation failed: %w", err) } return config, nil } // ValidateConfig checks if all required fields in the configuration are set func ValidateConfig(config *Config) error { if config.E621APIKey == "" { return fmt.Errorf("e621_API_KEY is not set") } if config.E621Username == "" { return fmt.Errorf("e621_USERNAME is not set") } if config.Neo4jURL == "" { return fmt.Errorf("NEO4J_URL is not set") } if config.Neo4jUsername == "" { return fmt.Errorf("NEO4J_USERNAME is not set") } if config.Neo4jPassword == "" { return fmt.Errorf("NEO4J_PASSWORD is not set") } return nil }