Documentation ¶
Index ¶
- func ExampleEnvGroups(groups []Group) string
- func ExampleEnvSettings(settings []Setting) string
- func ExampleYamlGroups(gs []Group) string
- func ExampleYamlSettings(settings []Setting) string
- func Load(ctx context.Context, s Source, settings []Setting) error
- func LoadGroups(ctx context.Context, s Source, groups []Group) error
- func NewComponent(ctx context.Context, s Source, v interface{}, destination interface{}) error
- func VerifyComponent(v interface{}) error
- type BaseSetting
- type BoolSetting
- type BoolSliceSetting
- type DurationSetting
- type DurationSliceSetting
- type Float32Setting
- type Float64Setting
- type Group
- type Int16Setting
- type Int32Setting
- type Int64Setting
- type Int8Setting
- type IntSetting
- type IntSliceSetting
- type MapSource
- type MultiSource
- type PrefixSource
- type Setting
- type SettingGroup
- type Source
- type StringMapStringSetting
- type StringMapStringSliceSetting
- type StringSetting
- type StringSliceSetting
- type TimeSetting
- type Uint16Setting
- type Uint32Setting
- type Uint64Setting
- type Uint8Setting
- type UintSetting
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExampleEnvGroups ¶
ExampleEnvGroups renders a Group to ENV vars.
func ExampleEnvSettings ¶
ExampleEnvSettings renders a collection of settings as ENV vars.
func ExampleYamlGroups ¶
ExampleYamlGroups renders a Group to YAML.
func ExampleYamlSettings ¶
ExampleYamlSettings renders a collection of settings as YAML text.
func LoadGroups ¶
LoadGroups works similarly to Load except that it will operate recursively on all settings and groups in the given group. Each group name will be added as a path segment leading to an individual setting.
func NewComponent ¶
NewComponent is the entry point for the high-level api. This method manages much of the complexity of adding configuration to a system. The given context and source are used for all lookups of configuration data. The given value is an implementation of the component contract and the destination is a pointer created with new(T) where T is the output type (or equivalent convertible) to the element produced by the component contract implementation.
The component contract is an interface that all input values must conform to and is roughly equivalent to the Factory concept. Each instance of the component contract must define two methods: Setting() C and New(context.Context, C) (T, error). Due to the lack of generics in go, there's no way to describe this contract as an actual go interface that would benefit from static typing support. As a result, this method uses reflect to enforce the contract in order to allow for C to be any type that is convertible to configuration via the Convert() method and for T to be any type that your use case requires.
For example, the most minimal implementation of the contract would look like:
type Config struct {} type Result struct {} type Component struct {} func (*Component) Settings() *Config { return &Config{} } func (*Component) New(_ context.Context, c *Config) (*Result, error) { return &Result{}, nil }
From here, any number of settings and sub-trees may be added to Config, any methods or attributes may be added to Result, and any complexity in the creation of Result maybe be added to the Component.New method. To then use this basic example as a component you would:
r := new(Result) err := NewComponent(context.Background(), source, &Component{}, r)
If the resulting error is nil then the destination value, r in this case, now points to the output of the Component.New method. The method returns an error any time the given component does not satisfy the contract, any time the configuration loading fails, or if the Component.New returns an error.
func VerifyComponent ¶
func VerifyComponent(v interface{}) error
VerifyComponent checks if a given value implements the Component contract.
Types ¶
type BaseSetting ¶
BaseSetting implements the name and description aspects of any given setting.
func (*BaseSetting) Description ¶
func (s *BaseSetting) Description() string
Description returns the human description of a setting for help text.
func (*BaseSetting) Name ¶
func (s *BaseSetting) Name() string
Name returns the setting name as it appears in configuration.
type BoolSetting ¶
type BoolSetting struct { *BaseSetting BoolValue *bool }
BoolSetting manages an instance of bool
func NewBoolSetting ¶
func NewBoolSetting(name string, description string, fallback bool) *BoolSetting
NewBoolSetting creates a BoolSetting with the given default value.
func (*BoolSetting) SetValue ¶
func (s *BoolSetting) SetValue(v interface{}) error
SetValue changes the underlying bool.
func (*BoolSetting) Value ¶
func (s *BoolSetting) Value() interface{}
Value returns the underlying bool.
type BoolSliceSetting ¶
type BoolSliceSetting struct { *BaseSetting BoolSliceValue *[]bool }
BoolSliceSetting manages an instance of []bool
func NewBoolSliceSetting ¶
func NewBoolSliceSetting(name string, description string, fallback []bool) *BoolSliceSetting
NewBoolSliceSetting creates a BoolSliceSetting with the given default value.
func (*BoolSliceSetting) SetValue ¶
func (s *BoolSliceSetting) SetValue(v interface{}) error
SetValue changes the underlying []bool.
func (*BoolSliceSetting) Value ¶
func (s *BoolSliceSetting) Value() interface{}
Value returns the underlying []bool.
type DurationSetting ¶
type DurationSetting struct { *BaseSetting DurationValue *time.Duration }
DurationSetting manages an instance of time.Duration
func NewDurationSetting ¶
func NewDurationSetting(name string, description string, fallback time.Duration) *DurationSetting
NewDurationSetting creates a DurationSetting with the given default value.
func (*DurationSetting) SetValue ¶
func (s *DurationSetting) SetValue(v interface{}) error
SetValue changes the underlying time.Duration.
func (*DurationSetting) Value ¶
func (s *DurationSetting) Value() interface{}
Value returns the underlying time.Duration.
type DurationSliceSetting ¶
type DurationSliceSetting struct { *BaseSetting DurationSliceValue *[]time.Duration }
DurationSliceSetting manages an instance of []time.Duration
func NewDurationSliceSetting ¶
func NewDurationSliceSetting(name string, description string, fallback []time.Duration) *DurationSliceSetting
NewDurationSliceSetting creates a DurationSliceSetting with the given default value.
func (*DurationSliceSetting) SetValue ¶
func (s *DurationSliceSetting) SetValue(v interface{}) error
SetValue changes the underlying []time.Duration.
func (*DurationSliceSetting) Value ¶
func (s *DurationSliceSetting) Value() interface{}
Value returns the underlying []time.Duration.
type Float32Setting ¶
type Float32Setting struct { *BaseSetting Float32Value *float32 }
Float32Setting manages an instance of float32
func NewFloat32Setting ¶
func NewFloat32Setting(name string, description string, fallback float32) *Float32Setting
NewFloat32Setting creates a Float32Setting with the given default value.
func (*Float32Setting) SetValue ¶
func (s *Float32Setting) SetValue(v interface{}) error
SetValue changes the underlying float32.
func (*Float32Setting) Value ¶
func (s *Float32Setting) Value() interface{}
Value returns the underlying float32.
type Float64Setting ¶
type Float64Setting struct { *BaseSetting Float64Value *float64 }
Float64Setting manages an instance of float64
func NewFloat64Setting ¶
func NewFloat64Setting(name string, description string, fallback float64) *Float64Setting
NewFloat64Setting creates a Float64Setting with the given default value.
func (*Float64Setting) SetValue ¶
func (s *Float64Setting) SetValue(v interface{}) error
SetValue changes the underlying float64.
func (*Float64Setting) Value ¶
func (s *Float64Setting) Value() interface{}
Value returns the underlying float64.
type Group ¶
Group is a container for a collection of settings. The container can contain any number of nested sub-trees.
func Convert ¶
Convert a struct into a Group. This function recurses over all nested structs which are gathered as sub-trees.
func GroupFromComponent ¶
GroupFromComponent works like Convert to change a struct into a Group but is able to do so with an implementation of the Component contract.
type Int16Setting ¶
type Int16Setting struct { *BaseSetting Int16Value *int16 }
Int16Setting manages an instance of int16
func NewInt16Setting ¶
func NewInt16Setting(name string, description string, fallback int16) *Int16Setting
NewInt16Setting creates a Int16Setting with the given default value.
func (*Int16Setting) SetValue ¶
func (s *Int16Setting) SetValue(v interface{}) error
SetValue changes the underlying int16.
func (*Int16Setting) Value ¶
func (s *Int16Setting) Value() interface{}
Value returns the underlying int16.
type Int32Setting ¶
type Int32Setting struct { *BaseSetting Int32Value *int32 }
Int32Setting manages an instance of int32
func NewInt32Setting ¶
func NewInt32Setting(name string, description string, fallback int32) *Int32Setting
NewInt32Setting creates a Int32Setting with the given default value.
func (*Int32Setting) SetValue ¶
func (s *Int32Setting) SetValue(v interface{}) error
SetValue changes the underlying int32.
func (*Int32Setting) Value ¶
func (s *Int32Setting) Value() interface{}
Value returns the underlying int32.
type Int64Setting ¶
type Int64Setting struct { *BaseSetting Int64Value *int64 }
Int64Setting manages an instance of int64
func NewInt64Setting ¶
func NewInt64Setting(name string, description string, fallback int64) *Int64Setting
NewInt64Setting creates a Int64Setting with the given default value.
func (*Int64Setting) SetValue ¶
func (s *Int64Setting) SetValue(v interface{}) error
SetValue changes the underlying int64.
func (*Int64Setting) Value ¶
func (s *Int64Setting) Value() interface{}
Value returns the underlying int64.
type Int8Setting ¶
type Int8Setting struct { *BaseSetting Int8Value *int8 }
Int8Setting manages an instance of int8
func NewInt8Setting ¶
func NewInt8Setting(name string, description string, fallback int8) *Int8Setting
NewInt8Setting creates a Int8Setting with the given default value.
func (*Int8Setting) SetValue ¶
func (s *Int8Setting) SetValue(v interface{}) error
SetValue changes the underlying int8.
func (*Int8Setting) Value ¶
func (s *Int8Setting) Value() interface{}
Value returns the underlying int8.
type IntSetting ¶
type IntSetting struct { *BaseSetting IntValue *int }
IntSetting manages an instance of int
func NewIntSetting ¶
func NewIntSetting(name string, description string, fallback int) *IntSetting
NewIntSetting creates a IntSetting with the given default value.
func (*IntSetting) SetValue ¶
func (s *IntSetting) SetValue(v interface{}) error
SetValue changes the underlying int.
func (*IntSetting) Value ¶
func (s *IntSetting) Value() interface{}
Value returns the underlying int.
type IntSliceSetting ¶
type IntSliceSetting struct { *BaseSetting IntSliceValue *[]int }
IntSliceSetting manages an instance of []int
func NewIntSliceSetting ¶
func NewIntSliceSetting(name string, description string, fallback []int) *IntSliceSetting
NewIntSliceSetting creates a IntSliceSetting with the given default value.
func (*IntSliceSetting) SetValue ¶
func (s *IntSliceSetting) SetValue(v interface{}) error
SetValue changes the underlying []int.
func (*IntSliceSetting) Value ¶
func (s *IntSliceSetting) Value() interface{}
Value returns the underlying []int.
type MapSource ¶
type MapSource struct {
Map map[string]interface{}
}
MapSource implements the Source interface for any map[string]interface{}. This implementation is intended to support the most common configuration sources which would be JSON, YAML, and ENV.
Note: All keys should lower case (if applicable for the character set)
as lower case will also be applied to all lookup paths.
func NewEnvSource ¶
NewEnvSource uses the given environment to generate a configuration source. The "_" character is used as a delimeter and each one will result in a subtree.
func NewFileSource ¶
NewFileSource reads in the given file and parsing it with multiple encodings to find one that works.
func NewJSONSource ¶
NewJSONSource generates a config source from a JSON string.
func NewMapSource ¶
NewMapSource is the recommended way to create a MapSource instance. While they can be created with any map[string]interface{}, this constructor ensures that all keys of the map have a consistent case applied.
func NewYAMLSource ¶
NewYAMLSource generates a config source from a YAML string.
type MultiSource ¶
type MultiSource []Source
MultiSource is an ordered set of Sources from which to pull values. It will search until the first Source returns a found value or will return false for found.
type PrefixSource ¶
PrefixSource is a wrapper for other Source implementations that adds a path element to the front of every lookup.
type Setting ¶
type Setting interface { Name() string Description() string Value() interface{} SetValue(v interface{}) error }
Setting is a generic container for all configuration values. Each implementation should maintain its own internal typing.
type SettingGroup ¶
type SettingGroup struct { NameValue string DescriptionValue string GroupValues []Group SettingValues []Setting }
SettingGroup an implementation of Group. This component is predominantly used by the struct converter to map native types into Setting and Group types.
func (*SettingGroup) Description ¶
func (g *SettingGroup) Description() string
Description returns the group description.
func (*SettingGroup) Groups ¶
func (g *SettingGroup) Groups() []Group
Groups returns any sub-trees in the current group.
func (*SettingGroup) Name ¶
func (g *SettingGroup) Name() string
Name returns the group name as it appears in the configuration.
func (*SettingGroup) Settings ¶
func (g *SettingGroup) Settings() []Setting
Settings returns any settings attached directly to this group.
type Source ¶
Source is the main entry point for fetching configuration values. The boolean value must be false if the source is unable to find an entry for the given path. If found, the raw value is returned and it is the responsibility of the consumer to verify the type or quality of the value.
type StringMapStringSetting ¶ added in v0.4.0
type StringMapStringSetting struct { *BaseSetting StringMapStringValue *map[string]string }
StringMapStringSetting manages an instance of map[string]string.
func NewStringMapStringSetting ¶ added in v0.4.0
func NewStringMapStringSetting(name string, description string, fallback map[string]string) *StringMapStringSetting
NewStringMapStringSetting creates a StringMapStringSetting with the given default value.
func (*StringMapStringSetting) SetValue ¶ added in v0.4.0
func (m *StringMapStringSetting) SetValue(v interface{}) error
SetValue changes the underlying map[string][]string.
func (*StringMapStringSetting) Value ¶ added in v0.4.0
func (m *StringMapStringSetting) Value() interface{}
Value returns the underlying map[string][]string.
type StringMapStringSliceSetting ¶ added in v0.3.0
type StringMapStringSliceSetting struct { *BaseSetting StringMapStringSliceValue *map[string][]string }
StringMapStringSliceSetting manages an instance of map[string][]string.
func NewStringMapStringSliceSetting ¶ added in v0.3.0
func NewStringMapStringSliceSetting(name string, description string, fallback map[string][]string) *StringMapStringSliceSetting
NewStringMapStringSliceSetting creates a StringMapStringSliceSetting with the given default value.
func (*StringMapStringSliceSetting) SetValue ¶ added in v0.3.0
func (m *StringMapStringSliceSetting) SetValue(v interface{}) error
SetValue changes the underlying map[string][]string.
func (*StringMapStringSliceSetting) Value ¶ added in v0.3.0
func (m *StringMapStringSliceSetting) Value() interface{}
Value returns the underlying map[string][]string.
type StringSetting ¶
type StringSetting struct { *BaseSetting StringValue *string }
StringSetting manages an instance of string
func NewStringSetting ¶
func NewStringSetting(name string, description string, fallback string) *StringSetting
NewStringSetting creates a StringSetting with the given default value.
func (*StringSetting) SetValue ¶
func (s *StringSetting) SetValue(v interface{}) error
SetValue changes the underlying string.
func (*StringSetting) Value ¶
func (s *StringSetting) Value() interface{}
Value returns the underlying string.
type StringSliceSetting ¶
type StringSliceSetting struct { *BaseSetting StringSliceValue *[]string }
StringSliceSetting manages an instance of []string
func NewStringSliceSetting ¶
func NewStringSliceSetting(name string, description string, fallback []string) *StringSliceSetting
NewStringSliceSetting creates a StringSliceSetting with the given default value.
func (*StringSliceSetting) SetValue ¶
func (s *StringSliceSetting) SetValue(v interface{}) error
SetValue changes the underlying []string.
func (*StringSliceSetting) Value ¶
func (s *StringSliceSetting) Value() interface{}
Value returns the underlying []string.
type TimeSetting ¶
type TimeSetting struct { *BaseSetting TimeValue *time.Time }
TimeSetting manages an instance of time.Time
func NewTimeSetting ¶
func NewTimeSetting(name string, description string, fallback time.Time) *TimeSetting
NewTimeSetting creates a TimeSetting with the given default value.
func (*TimeSetting) SetValue ¶
func (s *TimeSetting) SetValue(v interface{}) error
SetValue changes the underlying time.Time.
func (*TimeSetting) Value ¶
func (s *TimeSetting) Value() interface{}
Value returns the underlying time.Time.
type Uint16Setting ¶
type Uint16Setting struct { *BaseSetting Uint16Value *uint16 }
Uint16Setting manages an instance of uint16
func NewUint16Setting ¶
func NewUint16Setting(name string, description string, fallback uint16) *Uint16Setting
NewUint16Setting creates a Uint16Setting with the given default value.
func (*Uint16Setting) SetValue ¶
func (s *Uint16Setting) SetValue(v interface{}) error
SetValue changes the underlying uint16.
func (*Uint16Setting) Value ¶
func (s *Uint16Setting) Value() interface{}
Value returns the underlying uint16.
type Uint32Setting ¶
type Uint32Setting struct { *BaseSetting Uint32Value *uint32 }
Uint32Setting manages an instance of uint32
func NewUint32Setting ¶
func NewUint32Setting(name string, description string, fallback uint32) *Uint32Setting
NewUint32Setting creates a Uint32Setting with the given default value.
func (*Uint32Setting) SetValue ¶
func (s *Uint32Setting) SetValue(v interface{}) error
SetValue changes the underlying uint32.
func (*Uint32Setting) Value ¶
func (s *Uint32Setting) Value() interface{}
Value returns the underlying uint32.
type Uint64Setting ¶
type Uint64Setting struct { *BaseSetting Uint64Value *uint64 }
Uint64Setting manages an instance of uint64
func NewUint64Setting ¶
func NewUint64Setting(name string, description string, fallback uint64) *Uint64Setting
NewUint64Setting creates a Uint64Setting with the given default value.
func (*Uint64Setting) SetValue ¶
func (s *Uint64Setting) SetValue(v interface{}) error
SetValue changes the underlying uint64.
func (*Uint64Setting) Value ¶
func (s *Uint64Setting) Value() interface{}
Value returns the underlying uint64.
type Uint8Setting ¶
type Uint8Setting struct { *BaseSetting Uint8Value *uint8 }
Uint8Setting manages an instance of uint8
func NewUint8Setting ¶
func NewUint8Setting(name string, description string, fallback uint8) *Uint8Setting
NewUint8Setting creates a Uint8Setting with the given default value.
func (*Uint8Setting) SetValue ¶
func (s *Uint8Setting) SetValue(v interface{}) error
SetValue changes the underlying uint8.
func (*Uint8Setting) Value ¶
func (s *Uint8Setting) Value() interface{}
Value returns the underlying uint8.
type UintSetting ¶
type UintSetting struct { *BaseSetting UintValue *uint }
UintSetting manages an instance of uint
func NewUintSetting ¶
func NewUintSetting(name string, description string, fallback uint) *UintSetting
NewUintSetting creates a UintSetting with the given default value.
func (*UintSetting) SetValue ¶
func (s *UintSetting) SetValue(v interface{}) error
SetValue changes the underlying uint.
func (*UintSetting) Value ¶
func (s *UintSetting) Value() interface{}
Value returns the underlying uint.