config

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package config loads explicit, typed application configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(v any) ([]byte, error)

Dump returns JSON with secret-tagged and sensitive-name fields redacted, recursively.

func EnvVariableNotSetError added in v1.1.0

func EnvVariableNotSetError(key string) error

EnvVariableNotSetError reports a required environment variable that is empty.

func GetBool

func GetBool(k string, f bool) bool

GetBool reads a boolean environment variable, returning the fallback on invalid input.

func GetDuration

func GetDuration(k string, f time.Duration) time.Duration

func GetInt

func GetInt(k string, f int) int

GetInt reads an integer environment variable, returning the fallback on invalid input.

func GetString

func GetString(k, f string) string

GetString reads an environment variable, returning the fallback when absent.

func GetStringSlice

func GetStringSlice(k string, f []string) []string

GetStringSlice reads comma-separated environment values or copies the fallback.

func Load

func Load(dst any, options ...Options) error

Load updates a struct only after all conversions and validation succeed. Tags are env, default, required, secret.

func OptionalBoolEnv added in v1.1.0

func OptionalBoolEnv(key string, fallback bool) (bool, error)

OptionalBoolEnv parses a boolean environment variable or fallback.

func OptionalCSVEnv added in v1.1.0

func OptionalCSVEnv(key string) ([]string, error)

OptionalCSVEnv parses a comma-separated environment variable, removing duplicates.

func OptionalDurationEnv added in v1.1.0

func OptionalDurationEnv(key string, fallback time.Duration) (time.Duration, error)

OptionalDurationEnv parses a positive duration environment variable.

func OptionalIntEnv added in v1.1.0

func OptionalIntEnv(key string, fallback, min, max int) (int, error)

OptionalIntEnv parses and bounds an integer environment variable.

func OptionalStringEnv added in v1.1.0

func OptionalStringEnv(key, fallback string) string

OptionalStringEnv returns a trimmed environment variable or fallback.

func RequiredStringEnv added in v1.1.0

func RequiredStringEnv(key string) (string, error)

RequiredStringEnv returns a trimmed non-empty environment variable.

func Validate

func Validate(value any) error

Validate checks required tags recursively and runs nested/root validation hooks after field checks.

func ValidateListenAddress added in v1.1.0

func ValidateListenAddress(key, address string) error

ValidateListenAddress validates a host:port listen address.

func ValidateOrigin added in v1.1.0

func ValidateOrigin(raw string) error

ValidateOrigin validates an HTTP origin without paths or credentials.

func ValidatePort added in v1.1.0

func ValidatePort(key, port string) error

ValidatePort validates a TCP port.

func ValidateServiceURL added in v1.1.0

func ValidateServiceURL(key, raw string, schemes ...string) error

ValidateServiceURL validates a URL against allowed schemes.

Types

type Options

type Options struct {
	Environment  string
	Overrides    map[string]io.Reader
	Values       map[string]string
	MaxFileBytes int64
	Prefix       string
	Lookup       func(string) (string, bool)
	File         io.Reader
	Validate     func(any) error
}

Options controls loading. Precedence is defaults, existing values/file, environment.

Jump to

Keyboard shortcuts

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