config

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package config provides config utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsProduction

func IsProduction(env string) bool

IsProduction returns true when env is production-like.

func SplitCSV

func SplitCSV(input string) []string

SplitCSV splits a comma-separated string into a list of trimmed values.

Types

type Config

type Config struct {
	Addr           string `env:"API_ADDR"`         // host:port|:port
	DatabaseURL    string `env:"DATABASE_URL"`     // required
	LogLevel       string `env:"LOG_LEVEL"`        // debug|info|warn|error
	MigrateOnStart bool   `env:"MIGRATE_ON_START"` // true|false
	MigrationsDir  string `env:"MIGRATIONS_DIR"`   // plain - means use embedded
	Env            string `env:"ENV"`              // development|staging|production

	// Optional rate-limit bypass for test/dev environments.
	RateLimitSkipEnabled               bool   `env:"RATE_LIMIT_SKIP_ENABLED"`                 // true|false
	RateLimitSkipHeader                string `env:"RATE_LIMIT_SKIP_HEADER"`                  // header name
	RateLimitAllowDangerousDevBypasses bool   `env:"RATE_LIMIT_ALLOW_DANGEROUS_DEV_BYPASSES"` // true|false
}

Config captures application configuration loaded from environment variables.

func LoadFromEnv

func LoadFromEnv(loader *Loader) (Config, error)

LoadFromEnv loads config from environment using an optional loader.

func MustLoadFromEnv

func MustLoadFromEnv() Config

MustLoadFromEnv loads config or panics if required values are missing.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader reads env vars with defaults and aggregates errors.

func NewLoader

func NewLoader() *Loader

NewLoader creates a loader backed by the default env adapter.

func (*Loader) Bool

func (l *Loader) Bool(key string, def bool) bool

Bool reads a bool env var with a default.

func (*Loader) CSV

func (l *Loader) CSV(key string) []string

CSV reads a comma-separated env var into a slice.

func (*Loader) Duration

func (l *Loader) Duration(key string, def time.Duration) time.Duration

Duration reads a duration env var with a default.

func (*Loader) Err

func (l *Loader) Err() error

Err returns aggregated errors, if any.

func (*Loader) Int

func (l *Loader) Int(key string, def int) int

Int reads an int env var with a default.

func (*Loader) Require

func (l *Loader) Require(key string) string

Require returns the env var or records an error if missing.

func (*Loader) String

func (l *Loader) String(key, def string) string

String reads a string env var with a default.

Jump to

Keyboard shortcuts

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