fix: used required field for verification
This commit is contained in:
parent
e0a312bffc
commit
7bf67372e9
@ -6,11 +6,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
E621APIKey string `env:"e621_API_KEY"`
|
E621APIKey string `env:"E621_API_KEY,required"`
|
||||||
E621Username string `env:"e621_USERNAME"`
|
E621Username string `env:"E621_USERNAME,required"`
|
||||||
Neo4jURL string `env:"NEO4J_URL"`
|
Neo4jURL string `env:"NEO4J_URL,required"`
|
||||||
Neo4jUsername string `env:"NEO4J_USERNAME"`
|
Neo4jUsername string `env:"NEO4J_USERNAME,required"`
|
||||||
Neo4jPassword string `env:"NEO4J_PASSWORD"`
|
Neo4jPassword string `env:"NEO4J_PASSWORD,required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConfig loads the configuration from environment variables
|
// LoadConfig loads the configuration from environment variables
|
||||||
@ -20,29 +20,5 @@ func LoadConfig() (*Config, error) {
|
|||||||
return nil, fmt.Errorf("error parsing configuration: %w", err)
|
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
|
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
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user