Documentation ¶
Index ¶
- func ReaderCacheNotify(s *ReaderCache, key string, newVal []byte)
- func ReaderCacheRefresh(s *ReaderCache, r Reader, OnFetchErr func(err error, key string))
- type Bool
- type CachedReader
- func (m *CachedReader) Close()
- func (m *CachedReader) Get(key string) ([]byte, error)
- func (m *CachedReader) ListConfig() map[string][]byte
- func (m *CachedReader) ReadFrom(r io.Reader) (n int64, err error)
- func (m *CachedReader) StoreConfig(toStore map[string][]byte)
- func (m *CachedReader) Watch(key string, callback func(string)) error
- func (m *CachedReader) WriteTo(w io.Writer) (int64, error)
- type ComboRefresher
- type CommandLine
- type Distconf
- func (c *Distconf) Bool(key string, defaultVal bool) *Bool
- func (c *Distconf) Close()
- func (c *Distconf) Duration(key string, defaultVal time.Duration) *Duration
- func (c *Distconf) Float(key string, defaultVal float64) *Float
- func (c *Distconf) Int(key string, defaultVal int64) *Int
- func (c *Distconf) Keys() []string
- func (c *Distconf) Str(key string, defaultVal string) *Str
- func (c *Distconf) Struct(key string, defaultVal interface{}) *Struct
- func (c *Distconf) Var() expvar.Var
- type Duration
- type Dynamic
- type DynamicReader
- type Env
- type Float
- type InMemory
- func (m *InMemory) Close()
- func (m *InMemory) Get(key string) ([]byte, error)
- func (m *InMemory) ListConfig() map[string][]byte
- func (m *InMemory) StoreConfig(toStore map[string][]byte)
- func (m *InMemory) Watch(key string, callback func(string)) error
- func (m *InMemory) Write(key string, value []byte) error
- type Int
- type JSONConfig
- type Logger
- type Reader
- type ReaderCache
- type ReaderWriter
- type Refreshable
- type Refresher
- type Str
- type Struct
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReaderCacheNotify ¶
func ReaderCacheNotify(s *ReaderCache, key string, newVal []byte)
ReaderCacheNotify notifies a readercache that a value changed. This function isn't public on the ReaderCache so structs can embed a ReaderCache directly without exposing notifyWatchers.
func ReaderCacheRefresh ¶
func ReaderCacheRefresh(s *ReaderCache, r Reader, OnFetchErr func(err error, key string))
ReaderCacheRefresh calls a Get on every value watched by the ReaderCache
Types ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool is a Boolean type config inside a Config. It uses strconv.ParseBool to parse the conf contents as either true for false
func (*Bool) MarshalJSON ¶
MarshalJSON converts the boolean into the JSON encoding of the boolean
type CachedReader ¶
type CachedReader struct { Fallback DynamicReader // contains filtered or unexported fields }
CachedReader allows bulk loading values and caching the result
func (*CachedReader) Get ¶
func (m *CachedReader) Get(key string) ([]byte, error)
Get will try fetching it from source. If you can, update in memory. If you can't, try to find it in memory and return that instead.
func (*CachedReader) ListConfig ¶
func (m *CachedReader) ListConfig() map[string][]byte
ListConfig returns all the cached values
func (*CachedReader) ReadFrom ¶
func (m *CachedReader) ReadFrom(r io.Reader) (n int64, err error)
ReadFrom loads a stored cache
func (*CachedReader) StoreConfig ¶
func (m *CachedReader) StoreConfig(toStore map[string][]byte)
StoreConfig overwrites the stored config
type ComboRefresher ¶
type ComboRefresher []Refreshable
ComboRefresher can refresh from multiple sources
func (ComboRefresher) Refresh ¶
func (c ComboRefresher) Refresh()
Refresh calls all refreshes at once
type CommandLine ¶
CommandLine gets distconf values from the command line
type Distconf ¶
Distconf gets configuration data from the first backing that has it
func (*Distconf) Bool ¶
Bool object that can be referenced to get boolean values from a backing config
func (*Distconf) Close ¶
func (c *Distconf) Close()
Close this config framework's readers. Config variable results are undefined after this call.
func (*Distconf) Duration ¶
Duration returns a duration object that calls ParseDuration() on the given key
func (*Distconf) Float ¶
Float object that can be referenced to get float values from a backing config
func (*Distconf) Int ¶
Int object that can be referenced to get integer values from a backing config
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration is a duration type config inside a Config.
func (*Duration) MarshalJSON ¶
MarshalJSON converts the duration into the JSON encoding of the duration
type Dynamic ¶
type Dynamic interface { // Watch should execute callback function whenever the key changes. The parameter to callback should be the // key's name. Watch(key string, callback func(string)) error }
A Dynamic config can change what it thinks a value is over time.
type DynamicReader ¶
DynamicReader is a reader that can also change
type Env ¶
type Env struct { // Prefix is a forced prefix in front of config variables Prefix string // OsGetenv is a stub for os.Getenv() OsGetenv func(string) string }
Env allows fetching configuration from the env
type Float ¶
type Float struct {
// contains filtered or unexported fields
}
Float is an float type config inside a Config.
func (*Float) MarshalJSON ¶
MarshalJSON converts the float into the JSON encoding of the float
type InMemory ¶
type InMemory struct {
// contains filtered or unexported fields
}
InMemory stores configuration in memory
func (*InMemory) Close ¶
func (m *InMemory) Close()
Close does nothing and exists to satisfy an interface
func (*InMemory) ListConfig ¶
ListConfig returns a copy of the currently stored config values
func (*InMemory) StoreConfig ¶
StoreConfig stores into memory the given values, only if there currently is not a copy
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int is an integer type config inside a Config.
func (*Int) MarshalJSON ¶
MarshalJSON converts the integer into the JSON encoding of the integer
type JSONConfig ¶
type JSONConfig struct {
// contains filtered or unexported fields
}
JSONConfig reads configuration from a JSON stream
func (*JSONConfig) Close ¶
func (j *JSONConfig) Close()
Close does nothing and exists to satisfy an interface
func (*JSONConfig) Get ¶
func (j *JSONConfig) Get(key string) ([]byte, error)
Get returns the key's value as read by JSON
func (*JSONConfig) Refresh ¶
func (j *JSONConfig) Refresh(input io.Reader) error
Refresh loads the configuration from a Reader
func (*JSONConfig) RefreshFile ¶
func (j *JSONConfig) RefreshFile(filename string) error
RefreshFile reloads the configuration from a file
type Reader ¶
type Reader interface { // Get should return the given config value. If the value does not exist, it should return nil, nil. Get(key string) ([]byte, error) Close() }
Reader can get a []byte value for a config key
type ReaderCache ¶
type ReaderCache struct {
// contains filtered or unexported fields
}
ReaderCache is a type of distconf reader that simply caches previous Get() values and updates watchers when a value changes
func (*ReaderCache) Watch ¶
func (s *ReaderCache) Watch(key string, callback func(string)) error
Watch registers a distconf watcher
func (*ReaderCache) WatchedKeys ¶
func (s *ReaderCache) WatchedKeys() []string
WatchedKeys copies the internal watched keys map's keys
type ReaderWriter ¶
A ReaderWriter can both read and write configuration information
type Refreshable ¶
type Refreshable interface {
Refresh()
}
Refreshable is any configuration that needs to be periodically refreshed
type Refresher ¶
type Refresher struct { WaitTime *Duration ToRefresh Refreshable // contains filtered or unexported fields }
A Refresher can refresh the values inside any Refreshable object
type Str ¶
type Str struct {
// contains filtered or unexported fields
}
Str is a string type config inside a Config.
func (*Str) MarshalJSON ¶
MarshalJSON converts the string into the JSON encoding of the string
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct allows distconf to atomically update sets of variables. The structure provided must be represented as a json object in the backend. The DefaultValue provided sets the type that the backend josn will be unmarshelled into.
func (*Struct) Get ¶
func (s *Struct) Get() interface{}
Get the current value. For structs this *must* be cast to the same type as the DefaultValue provided. Not matching the type will result in a runtime panic.
func (*Struct) MarshalJSON ¶
MarshalJSON converts the struct into the JSON encoding of the struct