Documentation
¶
Index ¶
- Variables
- type ChangedListener
- type Config
- func (config *Config) AddChangedListener(l ChangedListener)
- func (config *Config) AppendSource(srcs ...Source)
- func (config *Config) Bool(name string, def bool) (val bool, err error)
- func (config *Config) Duration(name string, def time.Duration) (val time.Duration, err error)
- func (config *Config) Float64(name string, def float64) (val float64, err error)
- func (config *Config) Int(name string, def int) (val int, err error)
- func (config *Config) Int64(name string, def int64) (val int64, err error)
- func (config *Config) PrependSource(srcs ...Source)
- func (config *Config) RemoveChangedListener(l ChangedListener) error
- func (config *Config) Shutdown()
- func (config *Config) String(name string, def string) (val string, err error)
- type Source
- type SourceMonitored
- type SrcMap
- func (sm *SrcMap) GetLastModified() (last time.Time)
- func (sm *SrcMap) GetMonitorFreq() (freq time.Duration)
- func (sm *SrcMap) GetProp(name string) (val string, ok bool)
- func (sm *SrcMap) Put(key string, val string)
- func (sm *SrcMap) PutAll(mapIn map[string]string)
- func (sm *SrcMap) SetMonitorFreq(freq time.Duration)
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound returned when an operation is attempted on a resource that doesn't exist, such as fetching a non-existing property name.
Functions ¶
This section is empty.
Types ¶
type ChangedListener ¶
type ChangedListener interface {
// Changed is called when one or more properties in a `SourceMonitored` has a
// changed value.
Changed(cfg *Config, src SourceMonitored)
}
ChangedListener interface is for receiving notifications when one or more properties within monitored config sources (SourceMonitored) have changed values.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config provides methods for retrieving property values from one or more configuration sources.
func (*Config) AddChangedListener ¶
func (config *Config) AddChangedListener(l ChangedListener)
AddChangedListener adds a listener that will receive notifications whenever one or more property values change within the config.
func (*Config) AppendSource ¶
AppendSource appends one or more `Sources` at the end of the list of sources such that the last source will be the source checked last when resolving a property value.
func (*Config) Bool ¶
Bool returns the value of the named prop as a `bool`. If the property is not found then the supplied default `def` and `ErrNotFound` are returned.
Supports (t, true, 1, y, yes) for true, and (f, false, 0, n, no) for false, all case-insensitive.
See config.String
func (*Config) Duration ¶
Duration returns the value of the named prop as a `time.Duration`, representing a span of time.
Units of measure are supported: ms, sec, min, hour, day, week, year. See config.UnitsToMillis for a complete list of units supported.
If the property is not found then the supplied default `def` and `ErrNotFound` are returned.
See config.String
func (*Config) Float64 ¶
Float64 returns the value of the named prop as a `float64`. If the property is not found then the supplied default `def` and `ErrNotFound` are returned.
See config.String
func (*Config) Int ¶
Int returns the value of the named prop as an `int`. If the property is not found then the supplied default `def` and `ErrNotFound` are returned.
See config.String
func (*Config) Int64 ¶
Int64 returns the value of the named prop as an `int64`. If the property is not found then the supplied default `def` and `ErrNotFound` are returned.
See config.String
func (*Config) PrependSource ¶
PrependSource inserts one or more `Sources` at the beginning of the list of sources such that the first source will be the source checked first when resolving a property value.
func (*Config) RemoveChangedListener ¶
func (config *Config) RemoveChangedListener(l ChangedListener) error
RemoveChangedListener removes all instances of a ChangedListener. Returns `ErrNotFound` if the listener was not present.
func (*Config) Shutdown ¶
func (config *Config) Shutdown()
Shutdown can be called to stop monitoring of all config sources.
func (*Config) String ¶
String returns the value of the named prop as a string. If the property is not found then the supplied default `def` and `ErrNotFound` are returned.
Each `Source` is checked, in the order they are added via `ApppendSource` and `PrependSource`, until a value for the property is found.
type Source ¶
type Source interface {
// GetProp fetches the value of a named property. The value is
// returned as a string unless the name is not found, in which
// case `ok=false` is returned.
GetProp(name string) (val string, ok bool)
}
Source is the interface required for any source of name/value pairs.
type SourceMonitored ¶
type SourceMonitored interface {
// GetLastModified returns the time of the latest modification to any
// property value within the source. If a source does not support
// modifying properties at runtime then the zero value for `Time`
// should be returned to ensure reload events are not generated.
GetLastModified() time.Time
// GetMonitorFreq returns the frequency as a `time.Duration` between
// checks for changes to this config source.
//
// Returning zero (or less) will temporarily suspend calls to `GetLastModified`
// and `GetMonitorFreq` will be called every 10 seconds until resumed, after which
// `GetMontitorFreq` will be called at a frequency roughly equal to the `time.Duration`
// returned.
GetMonitorFreq() time.Duration
}
SourceMonitored is the interface required for any config source that is monitored for changes.
type SrcMap ¶
type SrcMap struct {
// contains filtered or unexported fields
}
SrcMap is a configuration `Source` backed by a simple map.
func NewSrcMapFromMap ¶
NewSrcMapFromMap creates a `SrcMap` containing a copy of the specified map.
func (*SrcMap) GetLastModified ¶
GetLastModified returns the time of the latest modification to any property value within the source. If a source does not support modifying properties at runtime then the zero value for `Time` should be returned to ensure reload events are not generated.
func (*SrcMap) GetMonitorFreq ¶
GetMonitorFreq returns the frequency as a `time.Duration` between checks for changes to this config source. Defaults to 1 minute unless changed with `GetMonitorFreq`.
func (*SrcMap) GetProp ¶
GetProp fetches the value of a named property. The value is returned as a string unless the name is not found, in which case `ok=false` is returned.
func (*SrcMap) SetMonitorFreq ¶
SetMonitorFreq sets the frequency between checks for changes to this config source.