feat(enrichment): align config with other services for K8s deployment

- Update Config struct to use individual postgres connection components (ACB_POSTGRES_HOST, ACB_POSTGRES_PORT, etc.) instead of ACB_DATABASE_URL
- Add DatabaseURL() method to build connection string from components
- This matches the pattern used by acb-index-builder and other services

Closes: bf-1ghm

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-05-25 01:44:59 -04:00
parent 496e4fb3d9
commit a22b0b6aa3
2 changed files with 22 additions and 6 deletions

View file

@ -9,8 +9,12 @@ import (
// Config holds all configuration for the enrichment service.
type Config struct {
// Database
DatabaseURL string
DatabaseName string
PostgresHost string
PostgresPort int
PostgresUser string
PostgresPassword string
PostgresDatabase string
DatabaseName string
// LLM
LLMBaseURL string
@ -47,9 +51,14 @@ type Config struct {
// LoadConfig reads configuration from environment variables.
func LoadConfig() Config {
return Config{
DatabaseURL: envOr("ACB_DATABASE_URL", "postgres://localhost:5432/acb?sslmode=disable"),
DatabaseName: envOr("ACB_DATABASE_NAME", "acb"),
postgresPort := envInt("ACB_POSTGRES_PORT", 5432)
cfg := Config{
PostgresHost: envOr("ACB_POSTGRES_HOST", "localhost"),
PostgresPort: postgresPort,
PostgresUser: envOr("ACB_POSTGRES_USER", "acb"),
PostgresPassword: os.Getenv("ACB_POSTGRES_PASSWORD"),
PostgresDatabase: envOr("ACB_POSTGRES_DATABASE", "ai_code_battle"),
DatabaseName: envOr("ACB_DATABASE_NAME", "ai_code_battle"),
LLMBaseURL: envOr("ACB_LLM_BASE_URL", "https://api.openai.com/v1"),
LLMAPIKey: os.Getenv("ACB_LLM_API_KEY"),
@ -78,6 +87,13 @@ func LoadConfig() Config {
CycleTimeout: envDuration("ACB_ENRICHMENT_TIMEOUT", 25*time.Minute),
MaxLifetime: envDuration("ACB_ENRICHMENT_MAX_LIFETIME", 4*time.Hour),
}
return cfg
}
// DatabaseURL returns the PostgreSQL connection string.
func (c *Config) DatabaseURL() string {
return fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
c.PostgresHost, c.PostgresPort, c.PostgresUser, c.PostgresPassword, c.PostgresDatabase)
}
func envOr(key, fallback string) string {

View file

@ -25,7 +25,7 @@ func main() {
cfg := LoadConfig()
// Connect to PostgreSQL
db, err := sql.Open("postgres", cfg.DatabaseURL)
db, err := sql.Open("postgres", cfg.DatabaseURL())
if err != nil {
slog.Error("Failed to connect to PostgreSQL", "error", err)
os.Exit(1)