config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides an env-only configuration loader for paper-board services.

MustBind reads environment variables onto a service-defined struct via reflection over `env`, `default`, and `validate` struct tags. After binding, validator/v10 runs Struct() on the destination. Required fields with no env or default cause MustBind to log to stderr and exit non-zero.

Flags and config files are intentionally unsupported. Service binaries MAY accept positional/flag args via cobra for one-shot operations (e.g. migrator subcommands), but those flags MUST NOT override Config fields.

Example:

type Config struct {
    DatabaseURL string        `env:"DATABASE_URL" validate:"required,url"`
    ServerPort  int           `env:"SERVER_PORT" default:"8080" validate:"gte=1,lte=65535"`
    LogLevel    string        `env:"LOG_LEVEL" default:"info" validate:"oneof=debug info warn error"`
    Timeout     time.Duration `env:"TIMEOUT" default:"30s"`
    Tags        []string      `env:"TAGS" default:"a,b,c"`
    Debug       bool          `env:"DEBUG" default:"false"`
}

cfg := config.MustBind[Config]()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustBind

func MustBind[T any]() *T

MustBind populates a fresh T from environment variables, applies struct-tag defaults for unset env vars, then runs validator/v10. On any error it logs to stderr and calls os.Exit(1). T MUST be a struct type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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