Documentation
¶
Overview ¶
Package config loads explicit, typed application configuration.
Index ¶
- func Dump(v any) ([]byte, error)
- func EnvVariableNotSetError(key string) error
- func GetBool(k string, f bool) bool
- func GetDuration(k string, f time.Duration) time.Duration
- func GetInt(k string, f int) int
- func GetString(k, f string) string
- func GetStringSlice(k string, f []string) []string
- func Load(dst any, options ...Options) error
- func OptionalBoolEnv(key string, fallback bool) (bool, error)
- func OptionalCSVEnv(key string) ([]string, error)
- func OptionalDurationEnv(key string, fallback time.Duration) (time.Duration, error)
- func OptionalIntEnv(key string, fallback, min, max int) (int, error)
- func OptionalStringEnv(key, fallback string) string
- func RequiredStringEnv(key string) (string, error)
- func Validate(value any) error
- func ValidateListenAddress(key, address string) error
- func ValidateOrigin(raw string) error
- func ValidatePort(key, port string) error
- func ValidateServiceURL(key, raw string, schemes ...string) error
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvVariableNotSetError ¶ added in v1.1.0
EnvVariableNotSetError reports a required environment variable that is empty.
func GetBool ¶
GetBool reads a boolean environment variable, returning the fallback on invalid input.
func GetInt ¶
GetInt reads an integer environment variable, returning the fallback on invalid input.
func GetStringSlice ¶
GetStringSlice reads comma-separated environment values or copies the fallback.
func Load ¶
Load updates a struct only after all conversions and validation succeed. Tags are env, default, required, secret.
func OptionalBoolEnv ¶ added in v1.1.0
OptionalBoolEnv parses a boolean environment variable or fallback.
func OptionalCSVEnv ¶ added in v1.1.0
OptionalCSVEnv parses a comma-separated environment variable, removing duplicates.
func OptionalDurationEnv ¶ added in v1.1.0
OptionalDurationEnv parses a positive duration environment variable.
func OptionalIntEnv ¶ added in v1.1.0
OptionalIntEnv parses and bounds an integer environment variable.
func OptionalStringEnv ¶ added in v1.1.0
OptionalStringEnv returns a trimmed environment variable or fallback.
func RequiredStringEnv ¶ added in v1.1.0
RequiredStringEnv returns a trimmed non-empty environment variable.
func Validate ¶
Validate checks required tags recursively and runs nested/root validation hooks after field checks.
func ValidateListenAddress ¶ added in v1.1.0
ValidateListenAddress validates a host:port listen address.
func ValidateOrigin ¶ added in v1.1.0
ValidateOrigin validates an HTTP origin without paths or credentials.
func ValidatePort ¶ added in v1.1.0
ValidatePort validates a TCP port.
func ValidateServiceURL ¶ added in v1.1.0
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.