Documentation ¶
Overview ¶
Package loadcfg loads a configuration using an optional file and basic serialization with the standard struct tags, but then also loads values from the environment.
Environment variables are defined with some prefix given to the function such (eg. PREFIX) and then they can be used to set almost any type of field. Below is an example of a complicated set of structs that show how you could set the fields for each type.
type A struct { // PREFIX_INT=5 Int int `toml:"int"` // PREFIX_INTPTR=5 IntPtr *int `toml:"intptr"` // PREFIX_STRINGS="one,two,three" Strings []string `toml:"strings"` // PREFIX_TIME=RFC3339TimeString Time time.Time `toml:"time"` // PREFIX_MAP_KEYNAME_FLOAT=4.5 Map map[string]B `toml:"map"` // PREFIX_MAP_KEYNAME_FLOAT=4.5 MapPtr map[string]*B `toml:"mapptr"` // PREFIX_MAPPRIM_KEYNAME=1 MapPrim map[string]int `toml:"mapprim"` // PREFIX_MAPPRIMPTR_KEYNAME=2 MapPrimPtr map[string]*int `toml:"mapprimptr"` // PREFIX_SLICE_0_FLOAT=4.5 // PREFIX_SLICE_1_FLOAT=4.5 Slice []B `toml:"slice"` // PREFIX_SLICEPTR_0_FLOAT=4.5 SlicePtr []*B `toml:"sliceptr"` // PREFIX_STRUCT_FLOAT=4.5 Struct B `toml:"struct"` // PREFIX_STRUCTPTR_FLOAT=4.5 StructPtr *B `toml:"structptr"` // Ignored, cannot be set by env Ignored *B `toml:"-"` } type B struct { Float float64 `toml:"float"` }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.