config

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config loads and validates runtime configuration from the environment. All settings are twelve-factor: every field has an env var, a sensible default where one exists, and validation that fails fast at boot.

Index

Constants

View Source
const (
	EnvDevelopment = "development"
	EnvProduction  = "production"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminConfig

type AdminConfig struct {
	Enabled bool   `env:"ENABLED" envDefault:"false"`
	Host    string `env:"HOST" envDefault:"127.0.0.1"`
	Port    int    `env:"PORT" envDefault:"6060"`
	Token   string `env:"TOKEN"`
}

AdminConfig controls the separate introspection listener that exposes pprof and expvar. It is never mounted on the public server.

type AuthConfig

type AuthConfig struct {
	JWKSURL       string        `env:"JWKS_URL"`
	PublicKeyPath string        `env:"PUBLIC_KEY_PATH"`
	Issuer        string        `env:"ISSUER" envDefault:"forge"`
	Audience      string        `env:"AUDIENCE" envDefault:"forge"`
	DevTokenTTL   time.Duration `env:"DEV_TOKEN_TTL" envDefault:"24h"`
}

AuthConfig selects how bearer tokens are verified. Exactly one of JWKSURL or PublicKeyPath is expected in production; development falls back to an ephemeral in-memory key (see internal/auth).

type Config

type Config struct {
	Env       string          `env:"FORGE_ENV" envDefault:"development"`
	HTTP      HTTPConfig      `envPrefix:"FORGE_HTTP_"`
	Admin     AdminConfig     `envPrefix:"FORGE_ADMIN_"`
	Database  DatabaseConfig  `envPrefix:"FORGE_DB_"`
	Telemetry TelemetryConfig `envPrefix:"FORGE_OTEL_"`
	Auth      AuthConfig      `envPrefix:"FORGE_AUTH_"`
	Log       LogConfig       `envPrefix:"FORGE_LOG_"`
}

func Load

func Load() (Config, error)

Load reads the environment into a Config and validates it.

func (Config) IsProduction

func (c Config) IsProduction() bool

func (Config) ServiceVersion

func (c Config) ServiceVersion() string

func (Config) Validate

func (c Config) Validate() error

type DatabaseConfig

type DatabaseConfig struct {
	URL               string        `env:"URL" envDefault:"postgres://forge:forge@localhost:5432/forge?sslmode=disable"`
	MaxConns          int32         `env:"MAX_CONNS" envDefault:"10"`
	MinConns          int32         `env:"MIN_CONNS" envDefault:"2"`
	MaxConnLifetime   time.Duration `env:"MAX_CONN_LIFETIME" envDefault:"1h"`
	MaxConnIdleTime   time.Duration `env:"MAX_CONN_IDLE_TIME" envDefault:"30m"`
	HealthCheckPeriod time.Duration `env:"HEALTH_CHECK_PERIOD" envDefault:"1m"`
	ConnectTimeout    time.Duration `env:"CONNECT_TIMEOUT" envDefault:"10s"`
}

type HTTPConfig

type HTTPConfig struct {
	Host               string        `env:"HOST" envDefault:"0.0.0.0"`
	Port               int           `env:"PORT" envDefault:"8080"`
	ReadHeaderTimeout  time.Duration `env:"READ_HEADER_TIMEOUT" envDefault:"5s"`
	ReadTimeout        time.Duration `env:"READ_TIMEOUT" envDefault:"15s"`
	WriteTimeout       time.Duration `env:"WRITE_TIMEOUT" envDefault:"15s"`
	IdleTimeout        time.Duration `env:"IDLE_TIMEOUT" envDefault:"60s"`
	ShutdownTimeout    time.Duration `env:"SHUTDOWN_TIMEOUT" envDefault:"20s"`
	DrainDelay         time.Duration `env:"DRAIN_DELAY" envDefault:"2s"`
	CORSAllowedOrigins []string      `env:"CORS_ALLOWED_ORIGINS" envSeparator:","`
	RateLimitPerSecond float64       `env:"RATE_LIMIT_PER_SECOND" envDefault:"50"`
	RateLimitBurst     int           `env:"RATE_LIMIT_BURST" envDefault:"100"`
	MaxBodyBytes       int64         `env:"MAX_BODY_BYTES" envDefault:"1048576"`
}

type LogConfig

type LogConfig struct {
	Level  string `env:"LEVEL" envDefault:"info"`
	Format string `env:"FORMAT" envDefault:"json"`
}

type TelemetryConfig

type TelemetryConfig struct {
	ServiceName  string  `env:"SERVICE_NAME" envDefault:"forge"`
	OTLPEndpoint string  `env:"OTLP_ENDPOINT"`
	SampleRatio  float64 `env:"SAMPLE_RATIO" envDefault:"1.0"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL