Documentation
¶
Index ¶
- Variables
- func Bool(key Variable[bool], fallback bool) bool
- func Bytes(key Variable[[]byte], fallback []byte) []byte
- func Fallback[T comparable](value T, fallback T) T
- func Float32(key Variable[float32], fallback float32) float32
- func Float64(key Variable[float64], fallback float64) float64
- func Int(key Variable[int], fallback int) int
- func Int8(key Variable[int8], fallback int8) int8
- func Int16(key Variable[int16], fallback int16) int16
- func Int32(key Variable[int32], fallback int32) int32
- func Int64(key Variable[int64], fallback int64) int64
- func Load[T constraint](cfg *Config, key Variable[T], fallback T)
- func Runes(key Variable[[]rune], fallback []rune) []rune
- func String(key Variable[string], fallback string) string
- func Uint(key Variable[uint], fallback uint) uint
- func Uint8(key Variable[uint8], fallback uint8) uint8
- func Uint16(key Variable[uint16], fallback uint16) uint16
- func Uint32(key Variable[uint32], fallback uint32) uint32
- func Uint64(key Variable[uint64], fallback uint64) uint64
- func Uintptr(key Variable[uintptr], fallback uintptr) uintptr
- func Write[T constraint](cfg *Config, values map[Variable[T]]T) error
- type Config
- func (c *Config) Bool(key Variable[bool]) bool
- func (c *Config) Bytes(key Variable[[]byte]) []byte
- func (c *Config) Exists(keys ...any) error
- func (c *Config) Float32(key Variable[float32]) float32
- func (c *Config) Float64(key Variable[float64]) float64
- func (c *Config) Int(key Variable[int]) int
- func (c *Config) Int8(key Variable[int8]) int8
- func (c *Config) Int16(key Variable[int16]) int16
- func (c *Config) Int32(key Variable[int32]) int32
- func (c *Config) Int64(key Variable[int64]) int64
- func (c *Config) Runes(key Variable[[]rune]) []rune
- func (c *Config) String(key Variable[string]) string
- func (c *Config) Uint(key Variable[uint]) uint
- func (c *Config) Uint8(key Variable[uint8]) uint8
- func (c *Config) Uint16(key Variable[uint16]) uint16
- func (c *Config) Uint32(key Variable[uint32]) uint32
- func (c *Config) Uint64(key Variable[uint64]) uint64
- func (c *Config) Uintptr(key Variable[uintptr]) uintptr
- type MissingVariableError
- type Variable
Constants ¶
This section is empty.
Variables ¶
var ErrMissingVariable = errors.New("missing configuration variables")
Functions ¶
func Bool ¶
Bool takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Bytes ¶
Bytes takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Fallback ¶
func Fallback[T comparable](value T, fallback T) T
Fallback is a helper function that returns the fallback value if the provided value is empty. Only works on comparable types, which includes basic types like int, string, bool, etc.
func Float32 ¶
Float32 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Float64 ¶
Float64 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Int ¶
Int takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Int8 ¶
Int8 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Int16 ¶
Int16 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Int32 ¶
Int32 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Int64 ¶
Int64 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Load ¶ added in v1.0.1
Load is a generic function that loads an environment variable into the provided configuration, using the specified key and fallback value. It uses type assertions to determine the type of the key and fallback value, and registers the variable in the appropriate map of the configuration struct.
func Runes ¶
Runes takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func String ¶
String takes an environment key, and a fallback value. Returns environment value if it isn't unset.
func Uint ¶
Uint takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Uint8 ¶
Uint8 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Uint16 ¶
Uint16 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Uint32 ¶
Uint32 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Uint64 ¶
Uint64 takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
func Uintptr ¶
Uintptr takes an environment key, and a fallback value. Returns environment variable with converted type, or fallback value if it fails.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
config is a concrete implementation of the Config interface, holding maps for each type of configuration variable. It provides methods to retrieve values for each type and checks if all required keys are registered.
func Merge ¶
Merge combines multiple Config instances into a single Config instance. To ensure a consistent view of the source configurations, it locks all configuration types for reading during the merge operation.
type MissingVariableError ¶ added in v1.0.1
type MissingVariableError struct {
Keys []string
}
MissingVariableError is an error type that holds a list of missing configuration variable keys.
func (MissingVariableError) Error ¶ added in v1.0.1
func (e MissingVariableError) Error() string
Error implements the error interface for missingVariableError.
func (MissingVariableError) Unwrap ¶ added in v1.0.1
func (e MissingVariableError) Unwrap() error
Unwrap implements the Unwrap method for the error interface, allowing the error to be unwrapped to ErrMissingVariable.