AllAi/backend/go/internal/config/config.go
2025-11-14 21:54:04 +03:00

37 lines
756 B
Go

package config
import (
"fmt"
"os"
)
// Config carries runtime configuration for the HTTP server.
type Config struct {
Host string
Port string
ProviderKind string
}
// Load reads configuration from environment variables with sensible defaults.
func Load() Config {
cfg := Config{
Host: getenv("ALLAI_HTTP_HOST", "0.0.0.0"),
Port: getenv("ALLAI_HTTP_PORT", "8080"),
ProviderKind: getenv("ALLAI_PROVIDER", "mock"),
}
return cfg
}
// Address returns the host:port string used by net/http.
func (c Config) Address() string {
return fmt.Sprintf("%s:%s", c.Host, c.Port)
}
func getenv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok && value != "" {
return value
}
return fallback
}