Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIConfig

type APIConfig struct {
	RateLimit RateLimitConfig `toml:"rate_limit"`
	CORS      CORSConfig      `toml:"cors"`
}

APIConfig holds configuration for the REST API layer. It maps to the [api] section in forge.toml.

func DefaultAPIConfig

func DefaultAPIConfig() APIConfig

DefaultAPIConfig returns an APIConfig populated with sensible production defaults.

type AdminConfig

type AdminConfig struct {
	Port int `toml:"port"` // default: 9090
}

AdminConfig holds the admin/ops HTTP server settings

type CORSConfig

type CORSConfig struct {
	// Enabled toggles CORS handling. Default: true.
	Enabled bool `toml:"enabled"`

	// AllowedOrigins is the list of origins that are allowed to make requests.
	// An empty list denies all cross-origin requests. Do NOT use "*" with
	// AllowCredentials — the middleware will log a warning and disable credentials.
	AllowedOrigins []string `toml:"allowed_origins"`

	// AllowedMethods is the list of HTTP methods to allow. Defaults to the most
	// common CRUD methods.
	AllowedMethods []string `toml:"allowed_methods"`

	// AllowedHeaders is the list of non-simple headers to allow in requests.
	AllowedHeaders []string `toml:"allowed_headers"`

	// ExposedHeaders is the list of response headers accessible to JavaScript.
	// Includes rate limit headers so clients can implement back-off.
	ExposedHeaders []string `toml:"exposed_headers"`

	// AllowCredentials permits cookies and authorization headers in cross-origin
	// requests. Cannot be combined with a wildcard AllowedOrigins.
	AllowCredentials bool `toml:"allow_credentials"`

	// MaxAge is the number of seconds the browser may cache a preflight response.
	// Default: 600 (10 minutes).
	MaxAge int `toml:"max_age"`
}

CORSConfig holds cross-origin resource sharing settings.

type Config

type Config struct {
	Project  ProjectConfig  `toml:"project"`
	Database DatabaseConfig `toml:"database"`
	Tools    ToolsConfig    `toml:"tools"`
	Server   ServerConfig   `toml:"server"`
	Session  SessionConfig  `toml:"session"`
	Jobs     JobsConfig     `toml:"jobs"`
	SSE      SSEConfig      `toml:"sse"`
	Observe  ObserveConfig  `toml:"telemetry"`
	Admin    AdminConfig    `toml:"admin"`
	API      APIConfig      `toml:"api"`
}

Config represents the forge.toml configuration structure

func Default

func Default() Config

Default returns a Config with sensible defaults

func Load

func Load(path string) (*Config, error)

Load reads and parses a forge.toml file, then applies any FORGE_* env var overrides so environment variables always win over file-based config.

func (*Config) ApplyEnvOverrides

func (c *Config) ApplyEnvOverrides()

ApplyEnvOverrides overlays FORGE_* environment variables on top of any values loaded from forge.toml. Environment variables always win (12-factor app config, DEPLOY-01).

type DatabaseConfig

type DatabaseConfig struct {
	URL string `toml:"url"`
}

DatabaseConfig holds database connection settings

type JobsConfig

type JobsConfig struct {
	Enabled bool           `toml:"enabled"`
	Queues  map[string]int `toml:"queues"` // queue_name -> max_workers
}

JobsConfig holds background job processing settings

type ObserveConfig

type ObserveConfig struct {
	OTLPEndpoint string `toml:"otlp_endpoint"` // empty = stdout in dev
	LogLevel     string `toml:"log_level"`     // debug, info, warn, error
	LogFormat    string `toml:"log_format"`    // json or text
}

ObserveConfig holds observability and telemetry settings

type ProjectConfig

type ProjectConfig struct {
	Name    string `toml:"name"`
	Module  string `toml:"module"`
	Version string `toml:"version"`
}

ProjectConfig holds project-level settings

type RateLimitConfig

type RateLimitConfig struct {
	// Enabled toggles rate limiting globally. Default: true.
	Enabled bool `toml:"enabled"`

	// Default applies to unauthenticated requests (default: 100 req/min).
	Default TierConfig `toml:"default"`

	// Authenticated applies to requests with a valid bearer token (default: 1000 req/min).
	Authenticated TierConfig `toml:"authenticated"`

	// APIKey applies to requests with a valid API key (default: 5000 req/min).
	APIKey TierConfig `toml:"api_key"`
}

RateLimitConfig holds rate limiting settings for the API.

type SSEConfig

type SSEConfig struct {
	MaxTotalConnections int `toml:"max_total_connections"` // default: 5000
	MaxPerUser          int `toml:"max_per_user"`          // default: 10
	BufferSize          int `toml:"buffer_size"`           // default: 32
}

SSEConfig holds Server-Sent Events connection settings

type ServerConfig

type ServerConfig struct {
	Port int    `toml:"port"`
	Host string `toml:"host"`
}

ServerConfig holds server settings

type SessionConfig

type SessionConfig struct {
	// Secret is the HMAC signing key for session data integrity. Should be a
	// 32- or 64-byte random string. Not required when using pgxstore (server-
	// side storage), but reserved for future HMAC signing use.
	Secret string `toml:"secret"`

	// Secure controls whether the session cookie is sent only over HTTPS.
	// Set to true in production, false during local development.
	Secure bool `toml:"secure"`

	// Lifetime is the session duration expressed as a Go duration string
	// (e.g. "24h", "168h"). Defaults to 24h when empty.
	Lifetime string `toml:"lifetime"`
}

SessionConfig holds session cookie and store settings

type TierConfig

type TierConfig struct {
	// Tokens is the number of requests allowed per Interval.
	Tokens uint64 `toml:"tokens"`

	// Interval is a duration string controlling the bucket refill window (e.g. "1m", "1h").
	Interval string `toml:"interval"`
}

TierConfig defines the token bucket parameters for a single rate limit tier.

type ToolsConfig

type ToolsConfig struct {
	TemplVersion    string `toml:"templ_version"`
	SQLCVersion     string `toml:"sqlc_version"`
	TailwindVersion string `toml:"tailwind_version"`
	AtlasVersion    string `toml:"atlas_version"`
}

ToolsConfig holds tool version specifications

Jump to

Keyboard shortcuts

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