turash/bugulma/backend/pkg/config/config.go
Damir Mukimov f434b26dd4
Some checks failed
CI/CD Pipeline / frontend-lint (push) Successful in 1m38s
CI/CD Pipeline / backend-lint (push) Failing after 1m41s
CI/CD Pipeline / backend-build (push) Has been skipped
CI/CD Pipeline / frontend-build (push) Failing after 26s
CI/CD Pipeline / e2e-test (push) Has been skipped
Enhance configuration management and testing for backend
- Update .gitignore to selectively ignore pkg/ directories at the root level
- Modify CI workflow to verify all Go packages can be listed
- Introduce configuration management with a new config package, including loading environment variables
- Add comprehensive tests for configuration loading and environment variable handling
- Implement Neo4j database interaction functions with corresponding tests for data extraction
2025-12-26 13:18:00 +01:00

81 lines
2.2 KiB
Go

package config
import "os"
type Config struct {
ServerPort string
JWTSecret string
CORSOrigin string
// PostgreSQL configuration
PostgresHost string
PostgresPort string
PostgresUser string
PostgresPassword string
PostgresDB string
PostgresSSLMode string
// Neo4j configuration
Neo4jURI string
Neo4jUsername string
Neo4jPassword string
Neo4jDatabase string
Neo4jEnabled bool
// Redis configuration
RedisURL string
// Ollama configuration
OllamaURL string
OllamaModel string
OllamaUsername string
OllamaPassword string
// Google Maps API configuration
GoogleMapsAPIKey string
GoogleCloudProjectID string
}
func Load() *Config {
return &Config{
ServerPort: getEnv("SERVER_PORT", "8080"),
JWTSecret: getEnv("JWT_SECRET", "your-secret-key-change-in-production"),
CORSOrigin: getEnv("CORS_ORIGIN", "http://localhost:3000"),
// PostgreSQL defaults
PostgresHost: getEnv("POSTGRES_HOST", "localhost"),
PostgresPort: getEnv("POSTGRES_PORT", "5432"),
PostgresUser: getEnv("POSTGRES_USER", "bugulma"),
PostgresPassword: getEnv("POSTGRES_PASSWORD", "bugulma"),
PostgresDB: getEnv("POSTGRES_DB", "bugulma_city"),
PostgresSSLMode: getEnv("POSTGRES_SSLMODE", "disable"),
// Neo4j defaults (disabled by default)
Neo4jURI: getEnv("NEO4J_URI", "neo4j://localhost:7687"),
Neo4jUsername: getEnv("NEO4J_USERNAME", "neo4j"),
Neo4jPassword: getEnv("NEO4J_PASSWORD", "password"),
Neo4jDatabase: getEnv("NEO4J_DATABASE", "neo4j"),
Neo4jEnabled: getEnv("NEO4J_ENABLED", "false") == "true",
// Redis defaults
RedisURL: getEnv("REDIS_URL", "redis://localhost:6379"),
// Ollama defaults
OllamaURL: getEnv("OLLAMA_URL", "http://localhost:11434"),
OllamaModel: getEnv("OLLAMA_MODEL", "qwen2.5:7b"),
OllamaUsername: getEnv("OLLAMA_USERNAME", ""),
OllamaPassword: getEnv("OLLAMA_PASSWORD", ""),
// Google Maps API defaults
GoogleMapsAPIKey: getEnv("GOOGLE_KG_API_KEY", ""), // Reuse KG API key if it works for Geocoding
GoogleCloudProjectID: getEnv("GOOGLE_CLOUD_PROJECT_ID", ""),
}
}
func getEnv(key, fallback string) string {
if value := os.Getenv(key); value != "" {
return value
}
return fallback
}