Documentation
¶
Overview ¶
Code generated by "go run generate_coercers.go"; DO NOT EDIT.
Package venom aims to provide the basic building blocks of a configuration management library.
It exposes as many aspects as the standard lib will reasonably support.
Code generated by "go run generate_getters.go"; DO NOT EDIT.
Index ¶
- Constants
- Variables
- func Alias(from, to string)
- func Clear()
- func Debug() string
- func DefaultEnvironmentVariableKeyTranslator(b byte) byte
- func Find(key string) (interface{}, bool)
- func Get(key string) interface{}
- func GetBool(key string) bool
- func GetFloat32(key string) float32
- func GetFloat64(key string) float64
- func GetInt(key string) int
- func GetInt16(key string) int16
- func GetInt32(key string) int32
- func GetInt64(key string) int64
- func GetInt8(key string) int8
- func GetString(key string) string
- func GetUint(key string) uint
- func GetUint16(key string) uint16
- func GetUint32(key string) uint32
- func GetUint64(key string) uint64
- func GetUint8(key string) uint8
- func JSONLoader(r io.Reader) (map[string]interface{}, error)
- func LoadDirectory(dir string, recurse bool) error
- func LoadFile(name string) error
- func NoOpKeyTranslator(b byte) byte
- func RegisterExtension(ext string, loader IOFileLoader)
- func RegisterResolver(level ConfigLevel, r Resolver)
- func SetDefault(key string, value interface{})
- func SetLevel(level ConfigLevel, key string, value interface{})
- func SetOverride(key string, value interface{})
- func Unmarshal(data *Venom, dst interface{}) error
- type CoerceErr
- type ConfigLevel
- type ConfigLevelHeap
- type ConfigLevelMap
- type ConfigMap
- type ConfigStore
- type DefaultConfigStore
- func (s *DefaultConfigStore) Alias(from, to string)
- func (s *DefaultConfigStore) Clear()
- func (s *DefaultConfigStore) Debug() string
- func (s *DefaultConfigStore) Find(key string) (interface{}, bool)
- func (s *DefaultConfigStore) Merge(l ConfigLevel, data ConfigMap)
- func (s *DefaultConfigStore) RegisterResolver(level ConfigLevel, r Resolver)
- func (s *DefaultConfigStore) SetLevel(level ConfigLevel, key string, value interface{})
- func (s *DefaultConfigStore) Size() int
- type DefaultResolver
- type EnvironmentVariableResolver
- type ErrNoFileLoader
- type Event
- type FlagsetResolver
- type IOFileLoader
- type InvalidUnmarshalError
- type KeyTranslator
- type LoggableConfigStore
- func (l *LoggableConfigStore) Alias(from, to string)
- func (l *LoggableConfigStore) Clear()
- func (l *LoggableConfigStore) Debug() string
- func (l *LoggableConfigStore) Find(key string) (interface{}, bool)
- func (l *LoggableConfigStore) Merge(cl ConfigLevel, data ConfigMap)
- func (l *LoggableConfigStore) RegisterResolver(level ConfigLevel, r Resolver)
- func (l *LoggableConfigStore) SetLevel(level ConfigLevel, key string, value interface{})
- func (l *LoggableConfigStore) Size() int
- type Logger
- type Resolver
- type SafeConfigStore
- func (s *SafeConfigStore) Alias(from, to string)
- func (s *SafeConfigStore) Clear()
- func (s *SafeConfigStore) Debug() string
- func (s *SafeConfigStore) Find(key string) (interface{}, bool)
- func (s *SafeConfigStore) Merge(l ConfigLevel, data ConfigMap)
- func (s *SafeConfigStore) RegisterResolver(level ConfigLevel, r Resolver)
- func (s *SafeConfigStore) SetLevel(level ConfigLevel, key string, value interface{})
- func (s *SafeConfigStore) Size() int
- type StoreLogger
- type SubscriptionStore
- func (s *SubscriptionStore) Alias(from, to string)
- func (s *SubscriptionStore) Clear()
- func (s *SubscriptionStore) Close()
- func (s *SubscriptionStore) Debug() string
- func (s *SubscriptionStore) Find(key string) (interface{}, bool)
- func (s *SubscriptionStore) Merge(l ConfigLevel, data ConfigMap)
- func (s *SubscriptionStore) RegisterResolver(level ConfigLevel, r Resolver)
- func (s *SubscriptionStore) SetLevel(level ConfigLevel, key string, value interface{})
- func (s *SubscriptionStore) Size() int
- func (s *SubscriptionStore) Subscribe(key string) <-chan Event
- func (s *SubscriptionStore) Unsubscribe(key string) error
- type Venom
- func (v *Venom) Alias(from, to string)
- func (v *Venom) Clear()
- func (v *Venom) Debug() string
- func (v *Venom) Find(key string) (interface{}, bool)
- func (v *Venom) Get(key string) interface{}
- func (v *Venom) GetBool(key string) bool
- func (v *Venom) GetFloat32(key string) float32
- func (v *Venom) GetFloat64(key string) float64
- func (v *Venom) GetInt(key string) int
- func (v *Venom) GetInt16(key string) int16
- func (v *Venom) GetInt32(key string) int32
- func (v *Venom) GetInt64(key string) int64
- func (v *Venom) GetInt8(key string) int8
- func (v *Venom) GetString(key string) string
- func (v *Venom) GetUint(key string) uint
- func (v *Venom) GetUint16(key string) uint16
- func (v *Venom) GetUint32(key string) uint32
- func (v *Venom) GetUint64(key string) uint64
- func (v *Venom) GetUint8(key string) uint8
- func (v *Venom) LoadDirectory(dir string, recurse bool) error
- func (v *Venom) LoadFile(name string) error
- func (v *Venom) Merge(l ConfigLevel, data ConfigMap)
- func (v *Venom) RegisterResolver(level ConfigLevel, r Resolver)
- func (v *Venom) SetDefault(key string, value interface{})
- func (v *Venom) SetLevel(level ConfigLevel, key string, value interface{})
- func (v *Venom) SetOverride(key string, value interface{})
- func (v *Venom) Size() int
Examples ¶
Constants ¶
const ( TIME_FORMAT = "2006-01-02T15:04:05.999Z" LOG_NAME = "[venom]" )
Variables ¶
var Delim = defaultDelim
Delim is the delimiter used for separating nested key spaces. The default is to separate on "." characters.
var EnvSeparator = "_"
EnvSeparator is used as the delimiter for separating keys prior to looking them up in the current environment.
ie, an EnvSeparator of "_" will result in a lookup for "log.level" searching for an environment variable named "LOG_LEVEL".
var FlagSeparator = "-"
FlagSeparator is used as the delimiter for separating keys prior to looking up their value from a FlagSet.
ie, a FlagSeparator of "-" will result in a lookup for "log.level" searching for a flag named "log-level".
var YmBHaE = wfDcXl()
Functions ¶
func Alias ¶
func Alias(from, to string)
Alias registers an alias for a given key in the global venom instance
Example ¶
package main import ( "fmt" "github.com/immaterialk/venom" ) func main() { venom.SetDefault("log.enabled", true) venom.Alias("verbose", "log.enabled") fmt.Println(venom.Get("verbose")) }
Output: true
func Clear ¶
func Clear()
Clear removes all data from the ConfigMap and resets the heap of config levels
func Debug ¶
func Debug() string
Debug returns the current venom ConfigMap as a pretty-printed JSON string
func DefaultEnvironmentVariableKeyTranslator ¶
The DefaultEnvironmentVariableKeyTranslator is the default KeyTranslator used by the EnvironmentVariableResolver.
It is responsible for mapping arbitrary input keys to an environment variable to lookup. This is done by converting all characters to upper case.
func Find ¶
Find searches for the given key, returning the discovered value and a boolean indicating whether or not the key was found
Example ¶
package main import ( "fmt" "github.com/immaterialk/venom" ) func main() { key := "some.config" venom.SetDefault(key, 12) if val, ok := venom.Find(key); !ok { fmt.Printf("unable to find value for key %s", key) } else { fmt.Println(val) } }
Output: 12
func Get ¶
func Get(key string) interface{}
Get retrieves the requested key from the global venom instance
Example ¶
package main import ( "fmt" "github.com/immaterialk/venom" ) func main() { venom.SetDefault("log.level", "INFO") fmt.Printf("%v\n", venom.Get("log")) fmt.Printf("%v\n", venom.Get("log.level"))
Output: map[level:INFO] INFO
func GetFloat32 ¶
GetFloat32 attempts to cast the returned config value from the global Venom instance
func GetFloat64 ¶
GetFloat64 attempts to cast the returned config value from the global Venom instance
func GetString ¶
GetString attempts to cast the returned config value from the global Venom instance
func GetUint16 ¶
GetUint16 attempts to cast the returned config value from the global Venom instance
func GetUint32 ¶
GetUint32 attempts to cast the returned config value from the global Venom instance
func GetUint64 ¶
GetUint64 attempts to cast the returned config value from the global Venom instance
func JSONLoader ¶
JSONLoader is an IOFileLoader which loads JSON config data
func LoadDirectory ¶
LoadDirectory loads any config files found in the provided directory, optionally recursing into any sub-directories
func LoadFile ¶
LoadFile loads the file from the provided path into Venoms configs. If the file can't be opened, if no loader for the files extension exists, or if loading the file fails, an error is returned
func NoOpKeyTranslator ¶
The NoOpKeyTranslator is a KeyTranslator which returns all input bytes unmodified.
func RegisterExtension ¶
func RegisterExtension(ext string, loader IOFileLoader)
RegisterExtension registers an IOFileLoader for the provided file extension
func RegisterResolver ¶
func RegisterResolver(level ConfigLevel, r Resolver)
RegisterResolver registers a custom config resolver into the global venom instance
func SetDefault ¶
func SetDefault(key string, value interface{})
SetDefault sets the provided key and value into the global venom instance at the default level
Example ¶
package main import ( "fmt" "github.com/immaterialk/venom" ) func main() { venom.SetDefault("verbose", true) fmt.Println(venom.Get("verbose")) }
Output: true
func SetLevel ¶
func SetLevel(level ConfigLevel, key string, value interface{})
SetLevel is a generic key/value setter method. It sets the provided k/v at the specified level inside the global venom instance.
Example ¶
package main import ( "fmt" "github.com/immaterialk/venom" ) func main() { var MySuperImportantLevel = venom.OverrideLevel + 1 venom.SetLevel(MySuperImportantLevel, "verbose", true) venom.SetOverride("verbose", false) fmt.Println(venom.Get("verbose")) }
Output: true
func SetOverride ¶
func SetOverride(key string, value interface{})
SetOverride sets the provided key and value into the global venom instance at the override level
Example ¶
package main import ( "fmt" "github.com/immaterialk/venom" ) func main() { venom.SetDefault("verbose", true) venom.SetOverride("verbose", false) fmt.Println(venom.Get("verbose")) }
Output: false
Types ¶
type ConfigLevel ¶
type ConfigLevel int
ConfigLevel is a type alias used to identify various configuration levels
const ( DefaultLevel ConfigLevel = iota FileLevel EnvironmentLevel FlagLevel OverrideLevel ConfigLevel = 99 )
Default the default set of available config levels
type ConfigLevelHeap ¶
type ConfigLevelHeap []ConfigLevel
An ConfigLevelHeap is a max-heap of ConfigLevels
func NewConfigLevelHeap ¶
func NewConfigLevelHeap() *ConfigLevelHeap
NewConfigLevelHeap creates a pre-initialized ConfigLevelHeap instance
func (ConfigLevelHeap) Len ¶
func (h ConfigLevelHeap) Len() int
func (ConfigLevelHeap) Less ¶
func (h ConfigLevelHeap) Less(i, j int) bool
func (*ConfigLevelHeap) Pop ¶
func (h *ConfigLevelHeap) Pop() interface{}
Pop removes the right-most (lowest) value from the heap
func (*ConfigLevelHeap) Push ¶
func (h *ConfigLevelHeap) Push(x interface{})
Push pushes a new value onto the heap, inserting in sort order
func (ConfigLevelHeap) Swap ¶
func (h ConfigLevelHeap) Swap(i, j int)
type ConfigLevelMap ¶
type ConfigLevelMap map[ConfigLevel]ConfigMap
ConfigLevelMap is a mapping of config levels to the maps which contain various configuration values at those levels
type ConfigMap ¶
type ConfigMap map[string]interface{}
ConfigMap defines the inner map type which holds actual config data. These are nested under a ConfigLevel which determines their priority
type ConfigStore ¶
type ConfigStore interface { RegisterResolver(level ConfigLevel, r Resolver) SetLevel(level ConfigLevel, key string, value interface{}) Merge(l ConfigLevel, data ConfigMap) Alias(from, to string) Find(key string) (interface{}, bool) Clear() Debug() string Size() int }
The ConfigStore interface defines a type capable of performing basic operations required for configuration management within a venom instance.
func NewLoggableConfigStore ¶
func NewLoggableConfigStore() ConfigStore
NewLoggableConfigStore returns a ConfigStore with a default logging mechanism set to write to os.Stdout.
func NewLoggableConfigStoreWith ¶
func NewLoggableConfigStoreWith(l Logger) ConfigStore
NewLoggableConfigStore takes a Logger and returns a new ConfigStore with said interface as the logging mechanism used for read and writes.
func NewSafeConfigStore ¶
func NewSafeConfigStore() ConfigStore
NewSafeConfigStore returns a new SafeConfigStore.
type DefaultConfigStore ¶
type DefaultConfigStore struct {
// contains filtered or unexported fields
}
DefaultConfigStore is the minimum implementation of a ConfigStore. It is capable of storing and managing arbitrary configuration keys and values.
func NewDefaultConfigStore ¶
func NewDefaultConfigStore() *DefaultConfigStore
NewDefaultConfigStore returns a newly allocated DefaultConfigStore.
func (*DefaultConfigStore) Alias ¶
func (s *DefaultConfigStore) Alias(from, to string)
Alias registers an alias for a given key. This allows consumers to access the same config via a different key, increasing the backwards compatibility of an application.
func (*DefaultConfigStore) Clear ¶
func (s *DefaultConfigStore) Clear()
Clear removes all data from the ConfigLevelMap and resets the heap of config levels.
func (*DefaultConfigStore) Debug ¶
func (s *DefaultConfigStore) Debug() string
Debug returns the current venom ConfigLevelMap as a pretty-printed JSON string.
func (*DefaultConfigStore) Find ¶
func (s *DefaultConfigStore) Find(key string) (interface{}, bool)
Find searches for the given key, returning the discovered value and a boolean indicating whether or not the key was found
func (*DefaultConfigStore) Merge ¶
func (s *DefaultConfigStore) Merge(l ConfigLevel, data ConfigMap)
Merge merges the provided config map into the ConfigLevel l, allocating space for ConfigLevel l if the level hasn't already been allocated.
func (*DefaultConfigStore) RegisterResolver ¶
func (s *DefaultConfigStore) RegisterResolver(level ConfigLevel, r Resolver)
RegisterResolver registers a custom config resolver for the specified ConfigLevel.
Additionally, if the provided level is not already in the current collection of active config levels, it will be added automatically
func (*DefaultConfigStore) SetLevel ¶
func (s *DefaultConfigStore) SetLevel(level ConfigLevel, key string, value interface{})
SetLevel is a generic key/value setter method. It sets the provided k/v at the specified level inside the map, conditionally creating a new ConfigMap if one didn't previously exist.
func (*DefaultConfigStore) Size ¶
func (s *DefaultConfigStore) Size() int
Size returns the number of config levels stored in this ConfigStore.
type DefaultResolver ¶
type DefaultResolver struct{}
DefaultResolver is the default resolver function used to resolve configuration values for a level which does not specify a custom resolver.
type EnvironmentVariableResolver ¶
type EnvironmentVariableResolver struct { Prefix string Translator KeyTranslator }
An EnvironmentVariableResolver is a resolver specifically capable of adding additional context in the form of a prefix to any loaded environment variables
func (*EnvironmentVariableResolver) Resolve ¶
func (r *EnvironmentVariableResolver) Resolve(keys []string, _ ConfigMap) (val interface{}, ok bool)
Resolve is a Resolver implementation which attempts to load the requested configuration from an environment variable
Example ¶
package main import ( "fmt" "os" "github.com/immaterialk/venom" ) func main() { os.Setenv("LOG_LEVEL", "INFO") fmt.Println(venom.Get("log.level")) }
Output: INFO
type ErrNoFileLoader ¶
type ErrNoFileLoader struct {
// contains filtered or unexported fields
}
ErrNoFileLoader is the error returned when a file is attempted to be loaded without a matching extension IOFileLoader
func (ErrNoFileLoader) Error ¶
func (e ErrNoFileLoader) Error() string
Error implements the error interface and returns a custom error message for the current ErrNoFileLoader instance
type Event ¶
type Event struct { Key string Value interface{} }
An Event represents an update published to a ConfigStore. The Key represents the config value that was updated. The Value contains the value that the key was updated to.
type FlagsetResolver ¶
type FlagsetResolver struct { Flags *flag.FlagSet Arguments []string // contains filtered or unexported fields }
The FlagsetResolver is used to resolve configuration from a FlagSet using the standard flag library.
If no FlagSet is provided, then flag.Parse and flag.Lookup are used to pull values directly from os.Args. If a FlagSet is provided, then any arguments required when Parsing the FlagSet may also be specified, otherwise the arguments default to os.Args[1:].
func (*FlagsetResolver) Resolve ¶
func (r *FlagsetResolver) Resolve(keys []string, _ ConfigMap) (val interface{}, ok bool)
Resolve is a Resolver function and will lookup the requested config value from a FlagSet
Example ¶
package main import ( "flag" "fmt" "github.com/immaterialk/venom" ) func main() { fs := flag.NewFlagSet("example", flag.ContinueOnError) fs.String("log-level", "WARNING", "set log level") flagResolver := &venom.FlagsetResolver{ Flags: fs, Arguments: []string{"-log-level=INFO"}, } venom.RegisterResolver(venom.FlagLevel, flagResolver) fmt.Println(venom.Get("log.level")) }
Output: INFO
type IOFileLoader ¶
IOFileLoader is the function signature for a function which can load an io.Reader into a map[string]interface{}
type InvalidUnmarshalError ¶
InvalidUnmarshalError is an error returned when an an invalid destination value is provided to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)
func (InvalidUnmarshalError) Error ¶
func (e InvalidUnmarshalError) Error() string
type KeyTranslator ¶
A KeyTranslator is used for translating portions of config keys in a level-agnostic manner.
Functions like these may be useful for performing operations such as normalizing hyphens ('-') to underscores ('_') when performing environment variable lookups, or perhaps the inverse when performing command line flag lookups.
type LoggableConfigStore ¶
type LoggableConfigStore struct {
// contains filtered or unexported fields
}
LoggableConfigStore implements the ConfigStore interface and provides a log field for reference to a Logger which will log on reads and writes.
func (*LoggableConfigStore) Alias ¶
func (l *LoggableConfigStore) Alias(from, to string)
Alias registers an alias for a given key. This allows consumers to access the same config via a different key, increasing the backwards compatibility of an application.
func (*LoggableConfigStore) Clear ¶
func (l *LoggableConfigStore) Clear()
Clear removes all data from the ConfigLevelMap and resets the heap of config levels.
func (*LoggableConfigStore) Debug ¶
func (l *LoggableConfigStore) Debug() string
Debug returns the current venom ConfigLevelMap as a pretty-printed JSON string.
func (*LoggableConfigStore) Find ¶
func (l *LoggableConfigStore) Find(key string) (interface{}, bool)
Find searches for the given key, returning the discovered value and a boolean indicating whether or not the key was found
func (*LoggableConfigStore) Merge ¶
func (l *LoggableConfigStore) Merge(cl ConfigLevel, data ConfigMap)
Merge merges the provided config map into the ConfigLevel l, allocating space for ConfigLevel l if the level hasn't already been allocated.
func (*LoggableConfigStore) RegisterResolver ¶
func (l *LoggableConfigStore) RegisterResolver(level ConfigLevel, r Resolver)
RegisterResolver registers a custom config resolver for the specified ConfigLevel.
Additionally, if the provided level is not already in the current collection of active config levels, it will be added automatically
func (*LoggableConfigStore) SetLevel ¶
func (l *LoggableConfigStore) SetLevel(level ConfigLevel, key string, value interface{})
SetLevel is a generic key/value setter method. It sets the provided k/v at the specified level inside the map, conditionally creating a new ConfigMap if one didn't previously exist.
func (*LoggableConfigStore) Size ¶
func (l *LoggableConfigStore) Size() int
Size returns the number of config levels stored in this ConfigStore.
type Logger ¶
type Logger interface { LogWrite(level ConfigLevel, key string, val interface{}) LogRead(key string, val interface{}, bl bool) }
Logger is the interface a user must implement in order to be used by the LogableConfigStore.
func NewStoreLogger ¶
NewStoreLogger returns a Logger suitable for default use case.
type Resolver ¶
A Resolver is responsible for performing a lookup of a config returning the value stored for that config or an error.
type SafeConfigStore ¶
type SafeConfigStore struct {
// contains filtered or unexported fields
}
SafeConfigStore implements the ConfigStore interface and provides a store that is safe to read and write from multiple go routines.
func (*SafeConfigStore) Alias ¶
func (s *SafeConfigStore) Alias(from, to string)
Alias registers an alias for a given key. This allows consumers to access the same config via a different key, increasing the backwards compatibility of an application.
func (*SafeConfigStore) Clear ¶
func (s *SafeConfigStore) Clear()
Clear removes all data from the ConfigLevelMap and resets the heap of config levels.
func (*SafeConfigStore) Debug ¶
func (s *SafeConfigStore) Debug() string
Debug returns the current venom ConfigLevelMap as a pretty-printed JSON string.
func (*SafeConfigStore) Find ¶
func (s *SafeConfigStore) Find(key string) (interface{}, bool)
Find searches for the given key, returning the discovered value and a boolean indicating whether or not the key was found
func (*SafeConfigStore) Merge ¶
func (s *SafeConfigStore) Merge(l ConfigLevel, data ConfigMap)
Merge merges the provided config map into the ConfigLevel l, allocating space for ConfigLevel l if the level hasn't already been allocated.
func (*SafeConfigStore) RegisterResolver ¶
func (s *SafeConfigStore) RegisterResolver(level ConfigLevel, r Resolver)
RegisterResolver registers a custom config resolver for the specified ConfigLevel.
Additionally, if the provided level is not already in the current collection of active config levels, it will be added automatically
func (*SafeConfigStore) SetLevel ¶
func (s *SafeConfigStore) SetLevel(level ConfigLevel, key string, value interface{})
SetLevel is a generic key/value setter method. It sets the provided k/v at the specified level inside the map, conditionally creating a new ConfigMap if one didn't previously exist.
func (*SafeConfigStore) Size ¶
func (s *SafeConfigStore) Size() int
Size returns the number of config levels stored in this ConfigStore.
type StoreLogger ¶
StoreLogger is Venom's default Logger.
func (*StoreLogger) LogRead ¶
func (sl *StoreLogger) LogRead(key string, val interface{}, bl bool)
LogWrite is the default logging behavior of a LoggableConfigStore on an action to read a value in the ConfigStore.
func (*StoreLogger) LogWrite ¶
func (sl *StoreLogger) LogWrite(level ConfigLevel, key string, val interface{})
LogWrite is the default logging behavior of a LoggableConfigStore on an action to set a value in the ConfigStore.
type SubscriptionStore ¶
type SubscriptionStore struct {
// contains filtered or unexported fields
}
A SubscriptionStore allows callers to subscribe to specific key namespaces, allowing them to be notified when a config under that space is modified.
Key-spaces can be subscribed to via the Subscribe method, which return a channel over which events for that key-space are emitted. This means that an update to the config `db.host` would trigger an event to be emitted if a subscription existed on either `db` or `db.host`.
func NewSubscriptionStore ¶
func NewSubscriptionStore(s ConfigStore) (*SubscriptionStore, func())
NewSubscriptionStore returns a newly allocated SubscriptionStore which wraps the specified ConfigStore. The channels created by this method will be un-buffered by default. To customize the buffer size of these channels, see NewSubscriptionStoreWithSize.
func NewSubscriptionStoreWithSize ¶
func NewSubscriptionStoreWithSize(s ConfigStore, size int) (*SubscriptionStore, func())
NewSubscriptionStoreWithSize returns a newly allocated SubscriptionStore which wraps the provided ConfigStore as well as a closure which, when called, will close all channels managed by this SubscriptionStore. The size parameter of this function allows for the caller to toggle the buffer size of the channels created by this ConfigStore.
func (*SubscriptionStore) Alias ¶
func (s *SubscriptionStore) Alias(from, to string)
Alias registers an alias for a given key. This allows consumers to access the same config via a different key, increasing the backwards compatibility of an application.
func (*SubscriptionStore) Clear ¶
func (s *SubscriptionStore) Clear()
Clear removes all data from the ConfigLevelMap and resets the heap of config levels.
func (*SubscriptionStore) Close ¶
func (s *SubscriptionStore) Close()
Close iterates over all allocated channels, closes them, and removes the subscriptions from the map of event subscriptions.
func (*SubscriptionStore) Debug ¶
func (s *SubscriptionStore) Debug() string
Debug returns the current venom ConfigLevelMap as a pretty-printed JSON string.
func (*SubscriptionStore) Find ¶
func (s *SubscriptionStore) Find(key string) (interface{}, bool)
Find searches for the given key, returning the discovered value and a boolean indicating whether or not the key was found.
func (*SubscriptionStore) Merge ¶
func (s *SubscriptionStore) Merge(l ConfigLevel, data ConfigMap)
Merge merges the provided config map into the ConfigLevel l, allocating space for ConfigLevel l if the level hasn't already been allocated.
func (*SubscriptionStore) RegisterResolver ¶
func (s *SubscriptionStore) RegisterResolver(level ConfigLevel, r Resolver)
RegisterResolver registers a custom config resolver for the specified ConfigLevel.
Additionally, if the provided level is not already in the current collection of active config levels, it will be added automatically
func (*SubscriptionStore) SetLevel ¶
func (s *SubscriptionStore) SetLevel(level ConfigLevel, key string, value interface{})
SetLevel is a generic key/value setter method. It sets the provided k/v at the specified level inside the map, conditionally creating a new ConfigMap if one didn't previously exist.
Once written, a new event will be emitted by this Subscription store, if any matching key-spaces have subscription channels.
func (*SubscriptionStore) Size ¶
func (s *SubscriptionStore) Size() int
Size returns the number of config levels stored in this ConfigStore.
func (*SubscriptionStore) Subscribe ¶
func (s *SubscriptionStore) Subscribe(key string) <-chan Event
Subscribe returns a channel over which updates to any value located at, or under, the specified key will be emitted.
Note that if no buffer size was specified when the SubscriptionStore was created, the channels will default to being un-buffered.
Also note that multiple subscriptions to the same key will result in the same channel being returned. To clear an existing subscription and to close it's corresponding channel, use the Unsubscribe method.
Subscriptions to the root space (empty string) will result in events being emitted for any and all config updates.
func (*SubscriptionStore) Unsubscribe ¶
func (s *SubscriptionStore) Unsubscribe(key string) error
Unsubscribe removes an existing subscription. The removal of this subscription results in the subscription channel being closed, and the subscription being completely removed from this Store.
To remove all existing subscriptions, use Close.
type Venom ¶
type Venom struct {
Store ConfigStore
}
Venom is the configuration registry responsible for storing and managing arbitrary configuration keys and values.
func Default ¶
func Default() *Venom
Default returns a new venom instance with some default resolver configuration applied to it.
func DefaultSafe ¶
func DefaultSafe() *Venom
Default returns a new goroutine-safe venom instance with some default resolver configuration applied to it.
func New ¶
func New() *Venom
New returns a newly initialized Venom instance.
The internal config map is created empty, only allocating space for a given config level once a value is set to that level.
func NewLoggable ¶
func NewLoggable() *Venom
NewLoggable returns a Venom instance with a default log set to standard out.
func NewLoggableWith ¶
NewLoggable takes a Logger and returns a newly initialized Venom instance that will log to a Logger interface upon reads and writes.
func NewSafe ¶
func NewSafe() *Venom
NewSafe returns a newly initialized Venom instance that is safe to read and write from multiple goroutines.
The internal config map is created empty, only allocating space for a given config level once a value is set to that level.
func NewWithStore ¶
func NewWithStore(s ConfigStore) *Venom
NewWithStore returns a newly initialized Venom instance that wraps the provided ConfigStore.
func (*Venom) Alias ¶
Alias registers an alias for a given key. This allows consumers to access the same config via a different key, increasing the backwards compatibility of an application.
func (*Venom) Clear ¶
func (v *Venom) Clear()
Clear removes all data from the ConfigLevelMap and resets the heap of config levels
func (*Venom) Debug ¶
Debug returns the current venom ConfigLevelMap as a pretty-printed JSON string.
func (*Venom) Find ¶
Find searches for the given key, returning the discovered value and a boolean indicating whether or not the key was found
func (*Venom) GetBool ¶
GetBool attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of false will be returned.
func (*Venom) GetFloat32 ¶
GetFloat32 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetFloat64 ¶
GetFloat64 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetInt ¶
GetInt attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetInt16 ¶
GetInt16 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetInt32 ¶
GetInt32 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetInt64 ¶
GetInt64 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetInt8 ¶
GetInt8 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetString ¶
GetString attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of "" will be returned.
func (*Venom) GetUint ¶
GetUint attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetUint16 ¶
GetUint16 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetUint32 ¶
GetUint32 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetUint64 ¶
GetUint64 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) GetUint8 ¶
GetUint8 attempts to cast the returned config value from the current Venom instance.
If the key does not exist, or if the type contained in Venom can not be cast to the requested type, then the zero value of 0 will be returned.
func (*Venom) LoadDirectory ¶
LoadDirectory loads any config files found in the provided directory, optionally recursing into any sub-directories
func (*Venom) LoadFile ¶
LoadFile loads the file from the provided path into Venoms configs. If the file can't be opened, if no loader for the files extension exists, or if loading the file fails, an error is returned
func (*Venom) Merge ¶
func (v *Venom) Merge(l ConfigLevel, data ConfigMap)
Merge merges the provided config map into the ConfigLevel l, allocating space for ConfigLevel l if the level hasn't already been allocated.
func (*Venom) RegisterResolver ¶
func (v *Venom) RegisterResolver(level ConfigLevel, r Resolver)
RegisterResolver registers a custom config resolver for the specified ConfigLevel.
Additionally, if the provided level is not already in the current collection of active config levels, it will be added automatically
func (*Venom) SetDefault ¶
SetDefault sets the provided key and value into the DefaultLevel of the config collection.
func (*Venom) SetLevel ¶
func (v *Venom) SetLevel(level ConfigLevel, key string, value interface{})
SetLevel is a generic key/value setter method. It sets the provided k/v at the specified level inside the map, conditionally creating a new ConfigMap if one didn't previously exist.
func (*Venom) SetOverride ¶
SetOverride sets the provided key and value into the OverrideLevel of the config collection.