Documentation ¶
Overview ¶
Package onion is a layer based, pluggable config manager for golang. The goal is to have multiple layer and load value base on this layers. the first layer with the data is used to provide the response.
Index ¶
- func AddLayers(l ...Layer)
- func AddLayersContext(ctx context.Context, l ...Layer)
- func Get(key string) (interface{}, bool)
- func GetBool(key string) bool
- func GetBoolDefault(key string, def bool) bool
- func GetDelimiter() string
- func GetDuration(key string) time.Duration
- func GetDurationDefault(key string, def time.Duration) time.Duration
- func GetFloat32(key string) float32
- func GetFloat32Default(key string, def float32) float32
- func GetFloat64(key string) float64
- func GetFloat64Default(key string, def float64) float64
- func GetInt(key string) int
- func GetInt64(key string) int64
- func GetInt64Default(key string, def int64) int64
- func GetIntDefault(key string, def int) int
- func GetString(key string) string
- func GetStringDefault(key string, def string) string
- func GetStringSlice(key string) []string
- func RegisterDecoder(dec Decoder, formats ...string)
- func ReloadWatch() <-chan struct{}
- func SetDelimiter(d string)
- type Cipher
- type Decoder
- type Layer
- func NewEnvLayer(separator string, whiteList ...string) Layer
- func NewEnvLayerPrefix(separator string, prefix string) Layer
- func NewFileLayer(path string, c Cipher) (Layer, error)
- func NewFileLayerContext(ctx context.Context, path string, c Cipher) (Layer, error)
- func NewMapLayer(data map[string]interface{}) Layer
- func NewStreamLayer(r io.Reader, format string, c Cipher) (Layer, error)
- func NewStreamLayerContext(ctx context.Context, r io.Reader, format string, c Cipher) (Layer, error)
- type Onion
- func (o *Onion) AddLayers(l ...Layer)
- func (o *Onion) AddLayersContext(ctx context.Context, l ...Layer)
- func (o *Onion) Get(key string) (interface{}, bool)
- func (o *Onion) GetBool(key string) bool
- func (o *Onion) GetBoolDefault(key string, def bool) bool
- func (o *Onion) GetDelimiter() string
- func (o *Onion) GetDuration(key string) time.Duration
- func (o *Onion) GetDurationDefault(key string, def time.Duration) time.Duration
- func (o *Onion) GetFloat32(key string) float32
- func (o *Onion) GetFloat32Default(key string, def float32) float32
- func (o *Onion) GetFloat64(key string) float64
- func (o *Onion) GetFloat64Default(key string, def float64) float64
- func (o *Onion) GetInt(key string) int
- func (o *Onion) GetInt64(key string) int64
- func (o *Onion) GetInt64Default(key string, def int64) int64
- func (o *Onion) GetIntDefault(key string, def int) int
- func (o *Onion) GetString(key string) string
- func (o *Onion) GetStringDefault(key string, def string) string
- func (o *Onion) GetStringSlice(key string) []string
- func (o *Onion) LayersData() []map[string]interface{}
- func (o *Onion) ReloadWatch() <-chan struct{}
- func (o *Onion) SetDelimiter(d string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddLayersContext ¶
AddLayersContext add a new layer to global config
func GetBoolDefault ¶
GetBoolDefault return bool value from Onion. if the value is not exists or if tha value is not boolean, return the default
func GetDuration ¶
GetDuration is for getting duration from config, it cast both int and string to duration
func GetDurationDefault ¶
GetDurationDefault is a function to get duration from config. it support both string duration (like 1h3m2s) and integer duration
func GetFloat32 ¶
GetFloat32 return an float32 value, if the value is not there, then it returns zero value
func GetFloat32Default ¶
GetFloat32Default return an float32 value from Onion, if the value is not exists or its not a float32, default is returned
func GetFloat64 ¶
GetFloat64 return the float64 value from config, if its not there, return zero
func GetFloat64Default ¶
GetFloat64Default return an float64 value from Onion, if the value is not exists or if the value is not float64 then return the default
func GetInt64Default ¶
GetInt64Default return an int64 value from Onion, if the value is not exists or if the value is not int64 then return the default
func GetIntDefault ¶
GetIntDefault return an int value from Onion, if the value is not exists or its not an integer , default is returned
func GetStringDefault ¶
GetStringDefault get a string from Onion. if the value is not exists or if tha value is not string, return the default
func GetStringSlice ¶
GetStringSlice try to get a slice from the config, also it support comma separated value if there is no array at the key.
func RegisterDecoder ¶
RegisterDecoder add a new decoder to the system, json is registered out of the box
func SetDelimiter ¶
func SetDelimiter(d string)
SetDelimiter set the current delimiter on global config
Types ¶
type Decoder ¶
Decoder is a stream decoder to convert a stream into a map of config keys, json is supported out of the box
func GetDecoder ¶
GetDecoder returns the decoder based on its name, it may returns nil if the decoder is not registered
type Layer ¶
type Layer interface { // Load is called once to get the initial data, it can return nil if there is no initial data Load() map[string]interface{} // Watch is called as soon as the layer registered in the onion. if the layer is persistent // it can return nil or a closed channel // Also this function may called several time and should return the same channel each time // and should not block Watch() <-chan map[string]interface{} }
Layer is an interface to handle the load phase.
func NewEnvLayer ¶
NewEnvLayer create new layer using the whitelist of environment values.
func NewEnvLayerPrefix ¶
NewEnvLayerPrefix create new env layer, with all values with the same prefix TODO: No prefix loading
func NewFileLayer ¶
NewFileLayer create a new file layer. it choose the format base on the extension
func NewFileLayerContext ¶
NewFileLayerContext create a new file layer. it choose the format base on the extension
func NewMapLayer ¶
NewMapLayer returns a basic map layer, this layer is simply holds a map of values
func NewStreamLayer ¶
NewStreamLayer create new stream layer, see the NewStreamLayerContext
func NewStreamLayerContext ¶
func NewStreamLayerContext(ctx context.Context, r io.Reader, format string, c Cipher) (Layer, error)
NewStreamLayerContext try to create a layer based on a stream, the format should be a registered format (see RegisterDecoder) and if the Cipher is not nil, it pass data to cipher first. A nil cipher is accepted as plain cipher
type Onion ¶
type Onion struct {
// contains filtered or unexported fields
}
Onion is a layer base configuration system
func NewContext ¶
NewContext return a new Onion, context is used for watch
func (*Onion) AddLayersContext ¶
AddLayersContext add new layers to the end of config layers. last layer is loaded after all other layer
func (*Onion) GetBoolDefault ¶
GetBoolDefault return bool value from Onion. if the value is not exists or if tha value is not boolean, return the default
func (*Onion) GetDelimiter ¶
GetDelimiter return the delimiter for nested key
func (*Onion) GetDuration ¶
GetDuration is for getting duration from config, it cast both int and string to duration
func (*Onion) GetDurationDefault ¶
GetDurationDefault is a function to get duration from config. it support both string duration (like 1h3m2s) and integer duration
func (*Onion) GetFloat32 ¶
GetFloat32 return an float32 value, if the value is not there, then it returns zero value
func (*Onion) GetFloat32Default ¶
GetFloat32Default return an float32 value from Onion, if the value is not exists or its not a float32, default is returned
func (*Onion) GetFloat64 ¶
GetFloat64 return the float64 value from config, if its not there, return zero
func (*Onion) GetFloat64Default ¶
GetFloat64Default return an float64 value from Onion, if the value is not exists or if the value is not float64 then return the default
func (*Onion) GetInt ¶
GetInt return an int value, if the value is not there, then it return zero value
func (*Onion) GetInt64Default ¶
GetInt64Default return an int64 value from Onion, if the value is not exists or if the value is not int64 then return the default
func (*Onion) GetIntDefault ¶
GetIntDefault return an int value from Onion, if the value is not exists or its not an integer , default is returned
func (*Onion) GetStringDefault ¶
GetStringDefault get a string from Onion. if the value is not exists or if tha value is not string, return the default
func (*Onion) GetStringSlice ¶
GetStringSlice try to get a slice from the config, also it support comma separated value if there is no array at the key.
func (*Onion) LayersData ¶
LayersData is used to get all layers data at once, useful for test and also used in the config writer
func (*Onion) ReloadWatch ¶
func (o *Onion) ReloadWatch() <-chan struct{}
ReloadWatch returns a channel to watch new layer data change, it just work for once, after the first change the channel will be changed to a new channel (the old channel will be closed to signal all listeners)
func (*Onion) SetDelimiter ¶
SetDelimiter set the current delimiter
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
ciphers
|
|
secconf
Package secconf implements secconf encoding as specified in the following format: base64(gpg(gzip(data)))
|
Package secconf implements secconf encoding as specified in the following format: base64(gpg(gzip(data))) |
cli
|
|
layers
|
|
etcdlayer
Package etcdlayer is a layer to manage a configuration on a key inside the etcd, it watches the change on the key
|
Package etcdlayer is a layer to manage a configuration on a key inside the etcd, it watches the change on the key |
filewatchlayer
Package filewatchlayer is the file loader with watch for the file.
|
Package filewatchlayer is the file loader with watch for the file. |
loaders
|
|
properties
Package properties is used to handle properties file in Onion file layer.
|
Package properties is used to handle properties file in Onion file layer. |
toml
Package tomlloader is used to handle toml file in Onion file layer.
|
Package tomlloader is used to handle toml file in Onion file layer. |
toml-0.5.0
Package toml050loader is used to handle toml file in Onion file layer.
|
Package toml050loader is used to handle toml file in Onion file layer. |
yaml
Package yamlloader is used to handle yaml file in Onion stream layer.
|
Package yamlloader is used to handle yaml file in Onion stream layer. |