config

package
v0.0.0-...-610d9af Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: GPL-3.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Load(getenv func(string) string) (Config, error)

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

func (c Config) GitHubEnabled() bool

GitHubEnabled reports whether "Sign in with GitHub" is configured.

func (Config) LogValue

func (c Config) LogValue() slog.Value

LogValue lets the whole Config be logged at startup as one structured group.

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.

func (Secret) GoString

func (s Secret) GoString() string

GoString implements fmt.GoStringer (used by %#v).

func (Secret) LogValue

func (s Secret) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the underlying secret value.

func (Secret) String

func (s Secret) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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