data layer
This commit is contained in:
47
data-layer/api/internal/config/config.go
Normal file
47
data-layer/api/internal/config/config.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Package config loads runtime configuration from environment variables.
|
||||
//
|
||||
// Vars prefixed with ANALYTICS_ are owned by this service; un-prefixed ones
|
||||
// (POSTGRES_DSN, REDIS_ADDR, CLICKHOUSE_*) are shared with cdp-ingestion.
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/caarlos0/env/v11"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
HTTPAddr string `env:"ANALYTICS_HTTP_ADDR" envDefault:":4000"`
|
||||
LogLevel string `env:"ANALYTICS_LOG_LEVEL" envDefault:"info"`
|
||||
ShutdownTimeout time.Duration `env:"ANALYTICS_SHUTDOWN_TIMEOUT_SECONDS" envDefault:"30s"`
|
||||
|
||||
// Cache TTLs — configurable per query type.
|
||||
CacheTTLQuery time.Duration `env:"ANALYTICS_CACHE_TTL_QUERY_SECONDS" envDefault:"60s"`
|
||||
CacheTTLProfile time.Duration `env:"ANALYTICS_CACHE_TTL_PROFILE_SECONDS" envDefault:"30s"`
|
||||
|
||||
// Where ClickHouse SQL templates live on disk. Resolved relative to the
|
||||
// process working directory; default matches `cd api && go run ./cmd/server`.
|
||||
ClickHouseTemplatesDir string `env:"ANALYTICS_CH_TEMPLATES_DIR" envDefault:"../infra/clickhouse"`
|
||||
|
||||
// Custom SQL ClickHouse credentials — separate read-only user.
|
||||
ClickHouseSQLUser string `env:"ANALYTICS_CH_SQL_USER" envDefault:"analytics_ro"`
|
||||
ClickHouseSQLPassword string `env:"ANALYTICS_CH_SQL_PASSWORD"`
|
||||
|
||||
// Shared infra ----------------------------------------------------------
|
||||
PostgresDSN string `env:"POSTGRES_DSN,required"`
|
||||
RedisAddr string `env:"REDIS_ADDR" envDefault:"localhost:6379"`
|
||||
|
||||
ClickHouseAddr string `env:"CLICKHOUSE_ADDR" envDefault:"localhost:9000"`
|
||||
ClickHouseDB string `env:"CLICKHOUSE_DB" envDefault:"cdp"`
|
||||
ClickHouseUser string `env:"CLICKHOUSE_USER" envDefault:"default"`
|
||||
ClickHousePassword string `env:"CLICKHOUSE_PASSWORD"`
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
cfg := &Config{}
|
||||
if err := env.Parse(cfg); err != nil {
|
||||
return nil, fmt.Errorf("config load: %w", err)
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user