Documentation
¶
Overview ¶
Package config turns environment variables into a validated Config.
Why environment variables: the twelve-factor way. The same binary/container image runs in dev, CI and production, and only the environment differs. Secrets in particular must come from the environment (or a secrets manager), never from the repository or the image.
Load takes a getenv function instead of calling os.Getenv itself. Production passes os.Getenv; tests pass a map lookup, so no test ever touches (or races on) real process environment.
Index ¶
Constants ¶
const MinSecretBytes = 32
MinSecretBytes is the minimum JWT signing-key length. HS256 uses HMAC-SHA256, whose security is bounded by the key size; RFC 7518 requires a key at least as long as the hash output (256 bits = 32 bytes). Short keys make brute-forcing the signature realistic.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Addr string
DBPath string
JWTSecret Secret
JWTTTL time.Duration
LogLevel slog.Level
LogFormat string // "json" or "text"
RateRPS float64
RateBurst int
CORSOrigins []string
ShutdownTimeout time.Duration
// Cookie-session authentication (Better Auth-style mode).
SessionTTL time.Duration // how long a session lives after its last refresh
SessionUpdateAge time.Duration // minimum age before activity extends the session again
CookieSecure bool // Secure flag on cookies; only disable for plain-http local dev
PublicURL string // externally visible base URL: links in emails, OAuth callback
// Stricter limit for credential endpoints (sign-in, sign-up, password reset...).
AuthRateRPS float64
AuthRateBurst int
// GitHub OAuth is enabled only when both are set.
GitHubClientID string
GitHubClientSecret Secret
}
Config is the full runtime configuration of the service.
func Load ¶
Load reads and validates configuration. It reports ALL problems at once (errors.Join) so an operator fixes the whole environment in one go rather than one restart per mistake.
func (Config) GitHubEnabled ¶
GitHubEnabled reports whether "Sign in with GitHub" is configured.
type Secret ¶
type Secret string
Secret is a string that refuses to print itself. Every formatting path (%v, %+v, %#v, %s and slog) returns a placeholder, so logging the whole Config by accident cannot leak the key. Code that truly needs the value must call Reveal, which is easy to grep for in review.