Documentation
¶
Overview ¶
Package config provides configuration loading for the static web server. It supports TOML file loading, sensible defaults, and environment variable overrides.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheConfig ¶
type CacheConfig struct {
// Enabled turns the in-memory cache on or off. Default: true.
Enabled bool `toml:"enabled"`
// MaxBytes is the maximum total byte size for the cache. Default: 256 MB.
MaxBytes int64 `toml:"max_bytes"`
// MaxFileSize is the maximum individual file size to cache. Default: 10 MB.
MaxFileSize int64 `toml:"max_file_size"`
// TTL is an optional time-to-live for cache entries (0 means no expiry).
TTL time.Duration `toml:"ttl"`
}
CacheConfig holds in-memory cache settings.
type CompressionConfig ¶
type CompressionConfig struct {
// Enabled turns on response compression. Default: true.
Enabled bool `toml:"enabled"`
// MinSize is the minimum response size in bytes to compress. Default: 1024.
MinSize int `toml:"min_size"`
// Level is the gzip compression level (1–9). Default: 5.
Level int `toml:"level"`
// Precompressed enables serving pre-compressed .gz/.br sidecar files. Default: true.
Precompressed bool `toml:"precompressed"`
}
CompressionConfig controls response compression settings.
type Config ¶
type Config struct {
Server ServerConfig `toml:"server"`
Files FilesConfig `toml:"files"`
Cache CacheConfig `toml:"cache"`
Compression CompressionConfig `toml:"compression"`
Headers HeadersConfig `toml:"headers"`
Security SecurityConfig `toml:"security"`
}
Config is the top-level configuration struct for the static web server.
type FilesConfig ¶
type FilesConfig struct {
// Root is the directory to serve files from. Default: "./public".
Root string `toml:"root"`
// Index is the index filename served for directory requests. Default: "index.html".
Index string `toml:"index"`
// NotFound is the path (relative to Root) of the custom 404 page.
NotFound string `toml:"not_found"`
}
FilesConfig holds file-serving settings.
type HeadersConfig ¶
type HeadersConfig struct {
// ImmutablePattern is a glob pattern for files to mark as immutable (max-age + immutable).
ImmutablePattern string `toml:"immutable_pattern"`
// StaticMaxAge is the Cache-Control max-age for non-HTML static assets. Default: 3600.
StaticMaxAge int `toml:"static_max_age"`
// HTMLMaxAge is the Cache-Control max-age for HTML files. Default: 0.
HTMLMaxAge int `toml:"html_max_age"`
}
HeadersConfig controls HTTP response header settings.
type SecurityConfig ¶
type SecurityConfig struct {
// BlockDotfiles prevents serving files whose path components start with ".". Default: true.
BlockDotfiles bool `toml:"block_dotfiles"`
// DirectoryListing enables or disables directory index listing. Default: false.
DirectoryListing bool `toml:"directory_listing"`
// CORSOrigins is the list of allowed CORS origins.
CORSOrigins []string `toml:"cors_origins"`
// CSP is the Content-Security-Policy header value. Default: "default-src 'self'".
CSP string `toml:"csp"`
// ReferrerPolicy sets the Referrer-Policy header. Default: "strict-origin-when-cross-origin".
ReferrerPolicy string `toml:"referrer_policy"`
// PermissionsPolicy sets the Permissions-Policy header. Default: "geolocation=(), microphone=(), camera=()".
PermissionsPolicy string `toml:"permissions_policy"`
// HSTSMaxAge is the max-age value in seconds for the Strict-Transport-Security header.
// Only sent over HTTPS. Default: 31536000 (1 year). Set to 0 to disable HSTS.
HSTSMaxAge int `toml:"hsts_max_age"`
// HSTSIncludeSubdomains adds the includeSubDomains directive to the HSTS header.
HSTSIncludeSubdomains bool `toml:"hsts_include_subdomains"`
}
SecurityConfig controls security settings.
type ServerConfig ¶
type ServerConfig struct {
// Addr is the HTTP listen address. Default: ":8080".
Addr string `toml:"addr"`
// TLSAddr is the HTTPS listen address. Default: ":8443".
TLSAddr string `toml:"tls_addr"`
// TLSCert is the path to the TLS certificate file.
TLSCert string `toml:"tls_cert"`
// TLSKey is the path to the TLS private key file.
TLSKey string `toml:"tls_key"`
// ReadHeaderTimeout is the maximum duration for reading request headers.
// Protects against slow-loris attacks. Default: 5s.
ReadHeaderTimeout time.Duration `toml:"read_header_timeout"`
// ReadTimeout is the maximum duration for reading the entire request (headers + body).
ReadTimeout time.Duration `toml:"read_timeout"`
// WriteTimeout is the maximum duration for writing a response.
WriteTimeout time.Duration `toml:"write_timeout"`
// IdleTimeout is the maximum duration for keep-alive connections.
IdleTimeout time.Duration `toml:"idle_timeout"`
// ShutdownTimeout is how long to wait for in-flight requests during shutdown.
ShutdownTimeout time.Duration `toml:"shutdown_timeout"`
}
ServerConfig holds network and TLS settings.
Click to show internal directories.
Click to hide internal directories.