Documentation ¶
Overview ¶
Package config is an interface for dynamic configuration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultPollInterval = time.Second * 30 DefaultSourceName = "MICRO:CONFIG" )
Functions ¶
Types ¶
type ChangeSet ¶
type ChangeSet struct { // The time at which the last change occured Timestamp time.Time // The raw data set for the change Data []byte // Hash of the source data Checksum string // The source of this change; file, consul, etcd Source string }
ChangeSet represents a set an actual source
type Config ¶
type Config interface { // Config values Values // Config options Options() Options // Watch for changes Watch(path ...string) (Watcher, error) // Render config unusable Close() error // String name of config String() string }
Config is the top level config which aggregates a number of sources and provides a single merged interface.
type Option ¶
type Option func(o *Options)
func PollInterval ¶
PollInterval is the time interval at which the sources are polled to retrieve config.
func WithClient ¶
func WithReader ¶
WithReader is the reader used by config to parse ChangeSets, merge them and provide values. We're not as elegant here in terms of encoding.
func WithSource ¶
WithSource appends a source to our list of sources. This forms a hierarchy whereby all the configs are merged down with the last specified as favoured.
type Reader ¶
type Reader interface { // Parse ChangeSets Parse(...*ChangeSet) (*ChangeSet, error) // As values Values(*ChangeSet) (Values, error) // Name of parser; json String() string }
Reader takes a ChangeSet from a source and returns a single merged ChangeSet e.g reads ChangeSet as JSON and can merge down
type Source ¶
type Source interface { // Loads ChangeSet from the source Read() (*ChangeSet, error) // Watch for source changes // Returns the entire changeset Watch() (SourceWatcher, error) // Name of source String() string }
Source is the source from which config is loaded. This may be a file, a url, consul, etc.
func NewSource ¶
func NewSource(opts ...SourceOption) Source
type SourceOption ¶
type SourceOption func(o *SourceOptions)
func SourceClient ¶
func SourceClient(c client.Client) SourceOption
func SourceHosts ¶
func SourceHosts(hosts ...string) SourceOption
func SourceName ¶
func SourceName(n string) SourceOption
SourceName is an option to provide name of a file, a url, key within etcd, consul, zookeeper, etc.
type SourceOptions ¶
type SourceWatcher ¶
SourceWatcher allows you to watch a source for changes Next is a blocking call which returns the next ChangeSet update. Stop Renders the watcher unusable.
type Value ¶
type Value interface { Bool(def bool) bool Int(def int) int String(def string) string Float64(def float64) float64 Duration(def time.Duration) time.Duration StringSlice(def []string) []string StringMap(def map[string]string) map[string]string Scan(val interface{}) error Bytes() []byte }
Represent a value retrieved from the values loaded
type Values ¶
type Values interface { // The path could be a nested structure so // make it a composable. // Returns internal cached value Get(path ...string) Value // Sets internal cached value Set(val interface{}, path ...string) // Deletes internal cached value Del(path ...string) // Returns vals as bytes Bytes() []byte }
Values loaded within the config