Documentation
¶
Overview ¶
Package config handles application configuration loading and validation from environment variables, providing a type-safe configuration structure.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvBoolOrDefault ¶
EnvBoolOrDefault returns the bool value of the environment variable if set and valid, otherwise the fallback.
func EnvFloat64OrDefault ¶
EnvFloat64OrDefault returns the float64 value of the environment variable if set and valid, otherwise the fallback.
func EnvIntOrDefault ¶
EnvIntOrDefault returns the int value of the environment variable if set and valid, otherwise the fallback.
func EnvOrDefault ¶
envOrDefault returns the value of the environment variable if set, otherwise the fallback.
Types ¶
type AdminUIConfig ¶
type AdminUIConfig struct {
ListenAddr string // Address for admin UI server to listen on
APIBaseURL string // Base URL of the Management API
ManagementToken string // Token for accessing Management API
Enabled bool // Whether Admin UI is enabled
TemplateDir string // Directory for HTML templates (default: "web/templates")
}
AdminUIConfig holds configuration for the Admin UI server
type Config ¶
type Config struct {
// Server configuration
ListenAddr string // Address to listen on (e.g., ":8080")
RequestTimeout time.Duration // Timeout for upstream API requests
MaxRequestSize int64 // Maximum size of incoming requests in bytes
MaxConcurrentReqs int // Maximum number of concurrent requests
// Environment
APIEnv string // API environment: 'production', 'development', 'test'
// Database configuration
DatabasePath string // Path to the SQLite database file
DatabasePoolSize int // Number of connections in the database pool
// Authentication
ManagementToken string // Token for admin operations, used to access the management API
// API Provider configuration
APIConfigPath string // Path to the API providers configuration file
DefaultAPIProvider string // Default API provider to use
OpenAIAPIURL string // Base URL for OpenAI API (legacy support)
EnableStreaming bool // Whether to enable streaming responses from APIs
// Admin UI settings
AdminUIPath string // Base path for the admin UI
AdminUI AdminUIConfig // Admin UI server configuration
// Logging
LogLevel string // Log level (debug, info, warn, error)
LogFormat string // Log format (json, text)
LogFile string // Path to log file (empty for stdout)
// Audit logging
AuditEnabled bool // Enable audit logging for security events
AuditLogFile string // Path to audit log file (empty to disable)
AuditCreateDir bool // Create parent directories for audit log file
AuditStoreInDB bool // Store audit events in database for analytics
// Observability middleware
ObservabilityEnabled bool // Enable async observability middleware
ObservabilityBufferSize int // Buffer size for in-memory event bus
// ObservabilityMaxRequestBodyBytes caps how many bytes of request bodies are captured for observability events.
// This is only for the async event payload and does not affect the proxied request body.
ObservabilityMaxRequestBodyBytes int64
// ObservabilityMaxResponseBodyBytes caps how many bytes of response bodies are captured for observability events.
// This is only for the async event payload and does not affect the proxied response body.
ObservabilityMaxResponseBodyBytes int64
// CORS settings
CORSAllowedOrigins []string // Allowed origins for CORS
CORSAllowedMethods []string // Allowed methods for CORS
CORSAllowedHeaders []string // Allowed headers for CORS
CORSMaxAge time.Duration // Max age for CORS preflight responses
// Rate limiting
GlobalRateLimit int // Maximum requests per minute globally
IPRateLimit int // Maximum requests per minute per IP
// Distributed rate limiting
DistributedRateLimitEnabled bool // Enable Redis-backed distributed rate limiting
DistributedRateLimitPrefix string // Redis key prefix for rate limit counters
DistributedRateLimitKeySecret string // HMAC secret for hashing token IDs in Redis keys (security)
DistributedRateLimitWindow time.Duration // Sliding window duration for rate limiting
DistributedRateLimitMax int // Maximum requests per window
DistributedRateLimitFallback bool // Enable fallback to in-memory when Redis unavailable
// Monitoring
EnableMetrics bool // Whether to enable a lightweight metrics endpoint (provider-agnostic)
MetricsPath string // Path for metrics endpoint
// Cleanup
TokenCleanupInterval time.Duration // Interval for cleaning up expired tokens
// Project active guard configuration
EnforceProjectActive bool // Whether to enforce project active status (default: true)
ActiveCacheTTL time.Duration // TTL for project active status cache (e.g., 5s)
ActiveCacheMax int // Maximum entries in project active status cache (e.g., 10000)
// API key caching (hot path: per-request upstream auth lookup)
APIKeyCacheTTL time.Duration // TTL for per-project upstream API key cache (e.g., 30s)
APIKeyCacheMax int // Maximum entries for upstream API key cache (e.g., 10000)
// Event bus configuration
EventBusBackend string // Backend for event bus: "redis-streams" or "in-memory"
RedisAddr string // Redis server address (e.g., "localhost:6379")
RedisDB int // Redis database number (default: 0)
// Redis Streams configuration (when EventBusBackend = "redis-streams")
RedisStreamKey string // Redis stream key name (default: "llm-proxy-events")
RedisConsumerGroup string // Consumer group name (default: "llm-proxy-dispatchers")
RedisConsumerName string // Consumer name within the group (should be unique per instance)
RedisStreamMaxLen int64 // Max stream length (0 = unlimited, default: 10000)
RedisStreamBlockTime time.Duration // Block timeout for reading (default: 5s)
RedisStreamClaimTime time.Duration // Min idle time before claiming pending msgs (default: 30s)
RedisStreamBatchSize int64 // Batch size for reading messages (default: 100)
// Cache stats aggregation
CacheStatsBufferSize int // Buffer size for async cache stats aggregation (default: 1000)
// Usage stats aggregation
UsageStatsBufferSize int // Buffer size for async usage stats aggregation (default: 1000)
}
Config holds all application configuration values loaded from environment variables. It provides a centralized, type-safe way to access configuration throughout the application.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a configuration with default values
func LoadFromFile ¶
LoadFromFile loads configuration from a file (placeholder for future YAML/JSON support)