Documentation ¶
Index ¶
- Constants
- func AllowProviderOverride()
- func Env(prefix string)
- func ErrorProvider(name string, err error)
- func File(filename string)
- func FileCustom(filename string, fn func([]byte) ([]Item, error))
- func FileCustomRefresh(filename string, fn func([]byte) ([]Item, error))
- func FileList(dirname string)
- func FileRefresh(filename string)
- func FileTree(dirname string)
- func GetItemValue(key string) (string, error)
- func GetItemValueBool(key string) (bool, error)
- func GetItemValueDuration(key string) (time.Duration, error)
- func GetItemValueFloat(key string) (float64, error)
- func GetItemValueInt(key string) (int64, error)
- func GetItemValueUint(key string) (uint64, error)
- func InitFromEnvironment()
- func NotifyIsMuted() bool
- func NotifyMute()
- func NotifyUnmute()
- func NotifyWatchers()
- func RegisterProvider(name string, f Provider)
- func RegisterProviderFactory(name string, f func(string))
- func Watch() chan struct{}
- type ErrAmbiguousItem
- type ErrItemNotFound
- type ErrProvider
- type ErrUninitializedItemList
- type InMemoryProvider
- type Item
- func (s *Item) Key() string
- func (s Item) Priority() int64
- func (s *Item) UnmarshalJSON(b []byte) error
- func (s Item) Unmarshaled() (interface{}, error)
- func (s Item) Value() (string, error)
- func (s Item) ValueBool() (bool, error)
- func (s Item) ValueBytes() ([]byte, error)
- func (s Item) ValueDuration() (time.Duration, error)
- func (s Item) ValueFloat() (float64, error)
- func (s Item) ValueInt() (int64, error)
- func (s Item) ValueUint() (uint64, error)
- type ItemFilter
- func (s *ItemFilter) Apply(items *ItemList) *ItemList
- func (s *ItemFilter) GetFirstItem() (Item, error)
- func (s *ItemFilter) GetItem(key string) (Item, error)
- func (s *ItemFilter) GetItemList() (*ItemList, error)
- func (s *ItemFilter) GetItemValue(key string) (string, error)
- func (s *ItemFilter) GetItemValueBool(key string) (bool, error)
- func (s *ItemFilter) GetItemValueDuration(key string) (time.Duration, error)
- func (s *ItemFilter) GetItemValueFloat(key string) (float64, error)
- func (s *ItemFilter) GetItemValueInt(key string) (int64, error)
- func (s *ItemFilter) GetItemValueUint(key string) (uint64, error)
- func (s *ItemFilter) MustGetFirstItem() Item
- func (s *ItemFilter) MustGetItem(key string) Item
- func (s *ItemFilter) Rekey(rekeyF func(*Item) string) *ItemFilter
- func (s *ItemFilter) Reorder(reorderF func(*Item) int64) *ItemFilter
- func (s *ItemFilter) Slice(key string, keyF ...func(string) string) *ItemFilter
- func (s *ItemFilter) Squash() *ItemFilter
- func (s *ItemFilter) String() string
- func (s *ItemFilter) Transform(transformF func(*Item) (string, error)) *ItemFilter
- func (s *ItemFilter) Unmarshal(f func() interface{}) *ItemFilter
- type ItemList
- func (s *ItemList) GetItem(key string) (Item, error)
- func (s *ItemList) GetItemValue(key string) (string, error)
- func (s *ItemList) GetItemValueBool(key string) (bool, error)
- func (s *ItemList) GetItemValueDuration(key string) (time.Duration, error)
- func (s *ItemList) GetItemValueFloat(key string) (float64, error)
- func (s *ItemList) GetItemValueInt(key string) (int64, error)
- func (s *ItemList) GetItemValueUint(key string) (uint64, error)
- func (s *ItemList) Keys() []string
- func (s *ItemList) Len() int
- func (s *ItemList) Less(i, j int) bool
- func (s *ItemList) Swap(i, j int)
- type Provider
Constants ¶
const (
// ConfigEnvVar defines the environment variable used to set up the configuration providers via InitFromEnvironment
ConfigEnvVar = "CONFIGURATION_FROM"
)
Variables ¶
This section is empty.
Functions ¶
func AllowProviderOverride ¶
func AllowProviderOverride()
AllowProviderOverride allows multiple calls to RegisterProvider() with the same provider name. This is useful for controlled test cases, but is not recommended in the context of a real application.
func ErrorProvider ¶
ErrorProvider registers a configstore provider which always returns an error.
func File ¶
func File(filename string)
File registers a configstore provider which reads from the file given in parameter (static content).
func FileCustom ¶
FileCustom registers a configstore provider which reads from the file given in parameter, and loads the content using the given unmarshal function
func FileCustomRefresh ¶
FileCustomRefresh registers a configstore provider which reads from the file given in parameter, and loads the content using the given unmarshal function; and watches file stat for auto refresh
func FileList ¶
func FileList(dirname string)
FileList registers a configstore provider which reads from the files contained in the directory given in parameter. The content of the files should be JSON/YAML similar to the File provider.
func FileRefresh ¶
func FileRefresh(filename string)
FileRefresh registers a configstore provider which readfs from the file given in parameter (provider watches file stat for auto refresh, watchers get notified).
func FileTree ¶
func FileTree(dirname string)
FileTree registers a configstore provider which reads from the files contained in the directory given in parameter. A limited hierarchy is supported: files can either be top level (in which case the file name will be used as the item key), or nested in a single sub-directory (in which case the sub-directory name will be used as item key for all the files contained in it). The content of the files should be the plain data, with no envelope. Capitalization can be used to indicate item priority for sub-directories containing multiple items which should be differentiated. Capitalized = higher priority.
func GetItemValue ¶
GetItemValue fetches the full item list, merging the results from all providers, then returns a single item's value by key.
func GetItemValueBool ¶
GetItemValueBool fetches the full item list, merging the results from all providers, then returns a single item's value by key.
func GetItemValueDuration ¶
GetItemValueDuration fetches the full item list, merging the results from all providers, then returns a single item's value by key.
func GetItemValueFloat ¶
GetItemValueFloat fetches the full item list, merging the results from all providers, then returns a single item's value by key.
func GetItemValueInt ¶
GetItemValueInt fetches the full item list, merging the results from all providers, then returns a single item's value by key.
func GetItemValueUint ¶
GetItemValueUint fetches the full item list, merging the results from all providers, then returns a single item's value by key.
func InitFromEnvironment ¶
func InitFromEnvironment()
InitFromEnvironment initializes configuration providers via their name and an optional argument. Suitable provider factories should have been registered via RegisterProviderFactory for this to work. Built-in providers (File, FileList, FileTree, ...) are registered by default.
Valid example: CONFIGURATION_FROM=file:/etc/myfile.conf,file:/etc/myfile2.conf,filelist:/home/foobar/configs
func NotifyIsMuted ¶ added in v0.1.5
func NotifyIsMuted() bool
NotifyIsMuted reports whether notifications are currently muted.
func NotifyMute ¶ added in v0.1.5
func NotifyMute()
NotifyMute prevents configstore from notifying watchers on configuration changes, until MotifyUnmute() is called.
func NotifyUnmute ¶ added in v0.1.5
func NotifyUnmute()
NotifyUnmute allows configstore to resume notifications to watchers on configuration changes. This will trigger a notification to catch up any change done during the time spent mute.
func NotifyWatchers ¶
func NotifyWatchers()
NotifyWatchers is used by providers to notify of configuration changes. It unblocks all the watchers which are ranging over a watch channel.
func RegisterProvider ¶
RegisterProvider registers a provider
func RegisterProviderFactory ¶
RegisterProviderFactory registers a factory function so that InitFromEnvironment can properly instantiate configuration providers via name + argument.
Types ¶
type ErrAmbiguousItem ¶
type ErrAmbiguousItem string
func (ErrAmbiguousItem) Error ¶
func (e ErrAmbiguousItem) Error() string
type ErrItemNotFound ¶
type ErrItemNotFound string
func (ErrItemNotFound) Error ¶
func (e ErrItemNotFound) Error() string
type ErrProvider ¶
type ErrProvider string
func (ErrProvider) Error ¶
func (e ErrProvider) Error() string
type ErrUninitializedItemList ¶
type ErrUninitializedItemList string
func (ErrUninitializedItemList) Error ¶
func (e ErrUninitializedItemList) Error() string
type InMemoryProvider ¶
type InMemoryProvider struct {
// contains filtered or unexported fields
}
InMemoryProvider implements an in-memory configstore provider.
func InMemory ¶
func InMemory(name string) *InMemoryProvider
InMemory registers an InMemoryProvider with a given arbitrary name and returns it. You can append any number of items to it, see Add().
func (*InMemoryProvider) Add ¶
func (inmem *InMemoryProvider) Add(s ...Item) *InMemoryProvider
Add appends an item to the in-memory list.
func (*InMemoryProvider) Items ¶
func (inmem *InMemoryProvider) Items() (ItemList, error)
Items returns the in-memory item list. This is the function that gets called by configstore.
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item is a key/value pair with a priority attached. The initial priority is set by the provider, but can be modified (see Reorder).
func GetItem ¶
GetItem retrieves the full item list, merging the results from all providers, then returns a single item by key. If 0 or >=2 items are present with that key, it will return an error.
func NewItem ¶
NewItem creates a item object from key / value / priority values. It is meant to be used by provider implementations.
func (*Item) UnmarshalJSON ¶
UnmarshalJSON respects json.Unmarshaler
func (Item) Unmarshaled ¶
Unmarshaled returns the unmarshaled object produced by ItemFilter.Unmarshal, along with any error that was encountered in list processing (unmarshal, transform).
func (Item) Value ¶
Value returns the item value, along with any error that was encountered in list processing (unmarshal, transform).
func (Item) ValueBool ¶
ValueBool returns the item value, along with any error that was encountered in list processing (unmarshal, transform).
func (Item) ValueBytes ¶
ValueBytes returns the item value, along with any error that was encountered in list processing (unmarshal, transform). Data to be returned should be base64 encoded
func (Item) ValueDuration ¶
ValueDuration returns the item value, along with any error that was encountered in list processing (unmarshal, transform).
func (Item) ValueFloat ¶
ValueFloat returns the item value, along with any error that was encountered in list processing (unmarshal, transform).
type ItemFilter ¶
type ItemFilter struct {
// contains filtered or unexported fields
}
ItemFilter holds a list of manipulation steps to operate on an item list. It can be declared globally then used/applied on specific item lists later. By declaring it before actual use, you can make it available to other packages which can then use it to describe your filters / configuration (e.g. main for usage). See String().
func (*ItemFilter) Apply ¶
func (s *ItemFilter) Apply(items *ItemList) *ItemList
Apply applies the filter on an existing item list.
func (*ItemFilter) GetFirstItem ¶
func (s *ItemFilter) GetFirstItem() (Item, error)
GetFirstItem fetches the full item list, applies the filter, then returns the first item of the list.
func (*ItemFilter) GetItem ¶
func (s *ItemFilter) GetItem(key string) (Item, error)
GetItem fetches the full item list, applies the filter, then returns a single item by key.
func (*ItemFilter) GetItemList ¶
func (s *ItemFilter) GetItemList() (*ItemList, error)
GetItemList fetches the full item list, applies the filter, and returns the result.
func (*ItemFilter) GetItemValue ¶
func (s *ItemFilter) GetItemValue(key string) (string, error)
GetItemValue fetches the full item list, applies the filter, then returns a single item's value by key.
func (*ItemFilter) GetItemValueBool ¶
func (s *ItemFilter) GetItemValueBool(key string) (bool, error)
GetItemValueBool fetches the full item list, applies the filter, then returns a single item's value by key.
func (*ItemFilter) GetItemValueDuration ¶
func (s *ItemFilter) GetItemValueDuration(key string) (time.Duration, error)
GetItemValueDuration fetches the full item list, applies the filter, then returns a single item's value by key.
func (*ItemFilter) GetItemValueFloat ¶
func (s *ItemFilter) GetItemValueFloat(key string) (float64, error)
GetItemValueFloat fetches the full item list, applies the filter, then returns a single item's value by key.
func (*ItemFilter) GetItemValueInt ¶
func (s *ItemFilter) GetItemValueInt(key string) (int64, error)
GetItemValueInt fetches the full item list, applies the filter, then returns a single item's value by key.
func (*ItemFilter) GetItemValueUint ¶
func (s *ItemFilter) GetItemValueUint(key string) (uint64, error)
GetItemValueUint fetches the full item list, applies the filter, then returns a single item's value by key.
func (*ItemFilter) MustGetFirstItem ¶
func (s *ItemFilter) MustGetFirstItem() Item
MustGetFirstItem is similar to GetFirstItem, but always returns an Item object. The eventual error is stored inside, and returned when accessing the item's value. Useful for chaining calls.
func (*ItemFilter) MustGetItem ¶
func (s *ItemFilter) MustGetItem(key string) Item
MustGetItem is similar to GetItem, but always returns an Item object. The eventual error is stored inside, and returned when accessing the item's value. Useful for chaining calls.
func (*ItemFilter) Rekey ¶
func (s *ItemFilter) Rekey(rekeyF func(*Item) string) *ItemFilter
Rekey modifies item keys. The function parameter is called for each item in the item list, and the returned string is used as the new key.
func (*ItemFilter) Reorder ¶
func (s *ItemFilter) Reorder(reorderF func(*Item) int64) *ItemFilter
Reorder modifies item priority. The function parameter is called for each item in the item list, and the returned integer is used as the new priority.
func (*ItemFilter) Slice ¶
func (s *ItemFilter) Slice(key string, keyF ...func(string) string) *ItemFilter
Slice filters the list items, keeping only those matching key. You can optionally pass a list of modifier functions, to be invoked when applying the filter.
func (*ItemFilter) Squash ¶
func (s *ItemFilter) Squash() *ItemFilter
Squash filters the items in the item list, keeping only the items with the highest priority for each key.
func (*ItemFilter) String ¶
func (s *ItemFilter) String() string
String returns a description of the filter.
func (*ItemFilter) Transform ¶
func (s *ItemFilter) Transform(transformF func(*Item) (string, error)) *ItemFilter
Transform modifies item values. The function parameter is called for each item in the item list, and the returned string + error are the values which will be returned by item.Value().
func (*ItemFilter) Unmarshal ¶
func (s *ItemFilter) Unmarshal(f func() interface{}) *ItemFilter
Unmarshal tries to unmarshal (from JSON or YAML) all the items in the item list into objects returned by the factory f(). The results and errors will be stored to be handled later. See item.Unmarshaled().
type ItemList ¶
type ItemList struct { Items []Item // contains filtered or unexported fields }
ItemList is a list of items which can be manipulated by an ItemFilter
func GetItemList ¶
GetItemList retrieves the full item list, merging the results from all providers. It does NOT cache, it's the responsability of the providers to keep an in-ram representation if desired.
func (*ItemList) GetItem ¶
GetItem returns a single item, by key. If 0 or >=2 items are present with that key, it will return an error.
func (*ItemList) GetItemValue ¶
GetItemValue returns a single item value, by key. If 0 or >=2 items are present with that key, it will return an error.
func (*ItemList) GetItemValueBool ¶
GetItemValueBool returns a single item value, by key. If 0 or >=2 items are present with that key, it will return an error.
func (*ItemList) GetItemValueDuration ¶
GetItemValueDuration returns a single item value, by key. If 0 or >=2 items are present with that key, it will return an error.
func (*ItemList) GetItemValueFloat ¶
GetItemValueFloat returns a single item value, by key. If 0 or >=2 items are present with that key, it will return an error.
func (*ItemList) GetItemValueInt ¶
GetItemValueInt returns a single item value, by key. If 0 or >=2 items are present with that key, it will return an error.
func (*ItemList) GetItemValueUint ¶
GetItemValueUint returns a single item value, by key. If 0 or >=2 items are present with that key, it will return an error.
type Provider ¶
A Provider retrieves config items and makes them available to the configstore, Their implementations can vary wildly (HTTP API, file, env, hardcoded test, ...) and their results will get merged by the configstore library. It's the responsability of the application using configstore to register suitable providers.