Documentation
¶
Overview ¶
Package cfgenv - Go package for loading config structs from environment vars
Index ¶
- func Example(w io.Writer, cfg any, options ...any) error
- func ExampleOf[T any](w io.Writer, options ...any) error
- func Load(cfg any, options ...any) error
- func LoadAs[T any](options ...any) (*T, error)
- func Write(w io.Writer, cfg any, options ...any) error
- type CustomSetterOption
- type ExpandOption
- type NamingOption
- type PrefixOption
- type SeparatorOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Example ¶
Example writes an example of the config
the supplied cfg arg must be a pointer to a struct
Use any options (such as PrefixOption, SeparatorOption, NamingOption or multiple CustomSetterOption) to alter loading behaviour
func ExampleOf ¶
ExampleOf writes an example of the specified T config
the type of T must be a struct
Use any options (such as PrefixOption, SeparatorOption, NamingOption or multiple CustomSetterOption) to alter loading behaviour
func Load ¶
Load loads a config struct from environment vars
the supplied cfg arg must be a pointer to a struct
Use any options (such as PrefixOption, SeparatorOption, NamingOption or multiple CustomSetterOption) to alter loading behaviour
Types ¶
type CustomSetterOption ¶
type CustomSetterOption interface {
// IsApplicable should return true if the fld type is supported by this custom setter
IsApplicable(fld reflect.StructField) bool
// Set sets the field value `v` using the environment var `raw` value
Set(fld reflect.StructField, v reflect.Value, raw string) error
}
CustomSetterOption is an option that can be passed to Load or LoadAs and provides support for reading additional struct field types
func NewDatetimeSetter ¶
func NewDatetimeSetter(format string) CustomSetterOption
type ExpandOption ¶ added in v1.1.0
ExpandOption is an option that can be passed to Load or LoadAs and provides support for expanding environment var values like...
FOO=${BAR}
func Expand ¶ added in v1.1.0
func Expand(lookups ...map[string]string) ExpandOption
Expand creates a default ExpandOption (for use in Load / LoadAs)
Any supplied lookup maps are checked first - if a given env var name, e.g. "${FOO}", is not found in lookups then the value is taken from env var
type NamingOption ¶
type NamingOption interface {
BuildName(prefix string, separator string, fld reflect.StructField, overrideName string) string
}
NamingOption is an option that can be passed to Load or LoadAs and provides a means of overriding how env var names are deduced
type PrefixOption ¶
type PrefixOption interface {
// GetPrefix returns the prefix for all env var names
GetPrefix() string
}
PrefixOption is an option that can be passed to Load or LoadAs and provides a prefix for all env var names
func NewPrefix ¶
func NewPrefix(prefix string) PrefixOption
NewPrefix creates a new PrefixOption with the specified prefix
type SeparatorOption ¶
type SeparatorOption interface {
// GetSeparator returns the separator to be used between prefixes used in env var names
GetSeparator() string
}
SeparatorOption is an option that can be passed to Load or LoadAs and provides the separator to be used between prefixes used in env var names
func NewSeparator ¶
func NewSeparator(separator string) SeparatorOption
NewSeparator creates a new NewSeparator with the specified separator
Directories
¶
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
basic
command
|
|
|
custom_setter_option
command
|
|
|
expand_option
command
|
|
|
naming_option
command
|
|
|
prefix_option
command
|
|
|
readme
command
|
|
|
separator_option
command
|
|
|
write_example
command
|