Documentation ¶
Overview ¶
Package config define instances an application provider that publicise services used to manage an application configuration.
Index ¶
- Constants
- Variables
- func Convert(val interface{}) interface{}
- type Config
- func (c *Config) Bool(path string, def ...bool) (bool, error)
- func (c *Config) Clone() Config
- func (c *Config) Config(path string, def ...Config) (IConfig, error)
- func (c *Config) Entries() []string
- func (c *Config) Float(path string, def ...float64) (float64, error)
- func (c *Config) Get(path string, def ...interface{}) (interface{}, error)
- func (c *Config) Has(path string) bool
- func (c *Config) Int(path string, def ...int) (int, error)
- func (c *Config) List(path string, def ...[]interface{}) ([]interface{}, error)
- func (c *Config) Merge(src Config)
- func (c *Config) Populate(path string, data interface{}, icase ...bool) (interface{}, error)
- func (c *Config) String(path string, def ...string) (string, error)
- type DecoderFactory
- type IConfig
- type IDecoder
- type IDecoderFactory
- type IDecoderStrategy
- type ILoader
- type IManager
- type IObsSource
- type IObserver
- type ISource
- type ISourceFactory
- type ISourceStrategy
- type Loader
- type Manager
- func (m *Manager) AddObserver(path string, callback IObserver) error
- func (m *Manager) AddSource(id string, priority int, src ISource) error
- func (m *Manager) Bool(path string, def ...bool) (bool, error)
- func (m *Manager) Close() error
- func (m *Manager) Config(path string, def ...Config) (IConfig, error)
- func (m *Manager) Entries() []string
- func (m *Manager) Float(path string, def ...float64) (float64, error)
- func (m *Manager) Get(path string, def ...interface{}) (interface{}, error)
- func (m *Manager) Has(path string) bool
- func (m *Manager) HasObserver(path string) bool
- func (m *Manager) HasSource(id string) bool
- func (m *Manager) Int(path string, def ...int) (int, error)
- func (m *Manager) List(path string, def ...[]interface{}) ([]interface{}, error)
- func (m *Manager) Populate(path string, data interface{}, icase ...bool) (interface{}, error)
- func (m *Manager) RemoveAllSources() error
- func (m *Manager) RemoveObserver(path string)
- func (m *Manager) RemoveSource(id string) error
- func (m *Manager) Source(id string) (ISource, error)
- func (m *Manager) SourcePriority(id string, priority int) error
- func (m *Manager) String(path string, def ...string) (string, error)
- type Provider
- type SourceFactory
Constants ¶
const ( // ID defines the id to be used as the container // registration id of a config instance, as a base id of all other config // package instances registered in the application container. ID = slate.ID + ".config" // DecoderStrategyTag defines the tag to be assigned to all // container decoders strategies. DecoderStrategyTag = ID + ".decoder.strategy" // DecoderFactoryID defines the id to be used as the // container registration id of a config decoder factory instance. DecoderFactoryID = ID + ".decoder.factory" // SourceStrategyTag defines the tag to be assigned to all // container source strategies. SourceStrategyTag = ID + ".source.strategy" // SourceFactoryID defines the id to be used as the // container registration id config source factory instance. SourceFactoryID = ID + ".source.factory" // LoaderID defines the id to be used as the container // registration id of a config loader instance. LoaderID = ID + ".loader" )
const ( // EnvID defines the slate.config package base environment variable name. EnvID = slate.EnvID + "_CONFIG" )
const ( // UnknownDecoderFormat defines the value to be used to // declare an unknown config source format. UnknownDecoderFormat = "unknown" )
const ( // UnknownSourceType defines the value to be used to declare an // unknown config source type. UnknownSourceType = "unknown" )
Variables ¶
var ( // DefaultFileFormat defines the file base config source def // format if the format is not present in the config. DefaultFileFormat = env.String(EnvID+"_DEFAULT_FILE_FORMAT", "yaml") // DefaultRestFormat defines the rest base config source def // format if the format is not present in the config. DefaultRestFormat = env.String(EnvID+"_DEFAULT_REST_FORMAT", "json") // PathSeparator defines the element(s) that will be used to split // a config path string into path elements. PathSeparator = env.String(EnvID+"_PATH_SEPARATOR", ".") // LoaderActive defines if the config loader should be executed // while the provider boot LoaderActive = env.Bool(EnvID+"_LOADER_ACTIVE", true) // LoaderSourceID defines the id to be used as the def of the // entry config source id to be used as the loader entry. LoaderSourceID = env.String(EnvID+"_LOADER_SOURCE_ID", "_sources") // LoaderSourcePath defines the entry config source path // to be used as the loader entry. LoaderSourcePath = env.String(EnvID+"_LOADER_SOURCE_PATH", "config/sources.yaml") // LoaderSourceFormat defines the entry config source format // to be used as the loader entry. LoaderSourceFormat = env.String(EnvID+"_LOADER_SOURCE_FORMAT", "yaml") // LoaderSourceListPath defines the entry config source path of // loading sources. LoaderSourceListPath = env.String(EnvID+"_LOADER_SOURCE_LIST_PATH", "slate.config.sources") // ObserveFrequency defines the id to be used as the def of a // config observable source frequency time in seconds. ObserveFrequency = env.Int(EnvID+"_OBSERVE_FREQUENCY", 0) )
var ( // ErrPathNotFound defines a path in Config not found error. ErrPathNotFound = fmt.Errorf("config path not found") // ErrInvalidFormat defines an error that signal an // unexpected/unknown config source decoder format. ErrInvalidFormat = fmt.Errorf("invalid config format") // ErrInvalidSource defines an error that signal an // unexpected/unknown config source type. ErrInvalidSource = fmt.Errorf("invalid config source") // ErrSourceNotFound defines a source config source not found error. ErrSourceNotFound = fmt.Errorf("config source not found") // ErrDuplicateSource defines a duplicate config source // registration attempt. ErrDuplicateSource = fmt.Errorf("config source already registered") )
Functions ¶
Types ¶
type Config ¶ added in v0.16.0
type Config map[interface{}]interface{}
Config defines a section of a configuration information
func (*Config) Bool ¶ added in v0.16.0
Bool will retrieve a value stored in the quested path cast to bool
func (*Config) Clone ¶ added in v0.16.0
Clone will instantiate an identical instance of the original Config
func (*Config) Config ¶ added in v0.16.0
Config will retrieve a value stored in the quested path cast to config
func (*Config) Entries ¶ added in v0.19.0
Entries will retrieve the list of stored entries in the configuration.
func (*Config) Float ¶ added in v0.16.0
Float will retrieve a value stored in the quested path cast to float
func (*Config) Get ¶ added in v0.16.0
Get will retrieve the value stored in the requested path. If the path does not exist, then the value nil will be returned. Or, if a def value was given as the optional extra argument, then it will be returned instead of the standard nil value.
func (*Config) Int ¶ added in v0.16.0
Int will retrieve a value stored in the quested path cast to int
func (*Config) List ¶ added in v0.16.0
List will retrieve a value stored in the quested path cast to list
func (*Config) Merge ¶ added in v0.22.0
Merge will increment the current config instance with the information stored in another config.
type DecoderFactory ¶ added in v0.16.0
type DecoderFactory []IDecoderStrategy
DecoderFactory defines a decoder instantiation factory.
func (*DecoderFactory) Create ¶ added in v0.16.0
func (f *DecoderFactory) Create( format string, args ...interface{}, ) (IDecoder, error)
Create will instantiate the requested new decoder capable to parse the formatted content into a usable configuration.
func (*DecoderFactory) Register ¶ added in v0.16.0
func (f *DecoderFactory) Register( strategy IDecoderStrategy, ) error
Register will store a new decoder factory strategy to be used to evaluate a request of an instance capable to parse a specific format. If the strategy accepts the format, then it will be used to instantiate the appropriate decoder that will be used to decode the configuration content.
type IConfig ¶
type IConfig interface { Entries() []string Has(path string) bool Get(path string, def ...interface{}) (interface{}, error) Bool(path string, def ...bool) (bool, error) Int(path string, def ...int) (int, error) Float(path string, def ...float64) (float64, error) String(path string, def ...string) (string, error) List(path string, def ...[]interface{}) ([]interface{}, error) Config(path string, def ...Config) (IConfig, error) Populate(path string, data any, icase ...bool) (any, error) }
IConfig defined an interface to an instance that holds configuration values
type IDecoder ¶
IDecoder interface defines the interaction methods to a config content decoder used to parse the source content into an application usable configuration Config instance.
type IDecoderFactory ¶
type IDecoderFactory interface { Register(strategy IDecoderStrategy) error Create(format string, args ...interface{}) (IDecoder, error) }
IDecoderFactory defined the interface of a config decoder factory instance.
func NewDecoderFactory ¶ added in v0.20.0
func NewDecoderFactory() IDecoderFactory
NewDecoderFactory will instantiate a new decoder factory instance.
type IDecoderStrategy ¶
type IDecoderStrategy interface { Accept(format string) bool Create(args ...interface{}) (IDecoder, error) }
IDecoderStrategy interface defines the methods of the decoder factory strategy that can validate creation requests and instantiation of a particular decoder.
type ILoader ¶
type ILoader interface {
Load() error
}
ILoader defines the interface of a config loader instance.
type IManager ¶
type IManager interface { io.Closer IConfig HasSource(id string) bool AddSource(id string, priority int, src ISource) error RemoveSource(id string) error RemoveAllSources() error Source(id string) (ISource, error) SourcePriority(id string, priority int) error HasObserver(path string) bool AddObserver(path string, callback IObserver) error RemoveObserver(path string) }
IManager defined an interface to an instance that manages configuration
func NewManager ¶
func NewManager() IManager
NewManager instantiate a new configuration object. This object will manage a series of sources, alongside of the ability of registration of configuration path/values observer callbacks that will be called whenever the value has changed.
type IObsSource ¶ added in v0.22.0
IObsSource interface extends the ISource interface with methods specific to sources that will be checked for updates in a regular periodicity defined in the config object where the source will be registered.
type IObserver ¶
type IObserver func(interface{}, interface{})
IObserver callback function used to be called when an observed configuration path has changed.
type ISource ¶
type ISource interface { Has(path string) bool Get(path string, def ...interface{}) (interface{}, error) }
ISource defines the base interface of a config source.
type ISourceFactory ¶
type ISourceFactory interface { Register(strategy ISourceStrategy) error Create(cfg IConfig) (ISource, error) }
ISourceFactory defined the interface of a config source factory instance.
func NewSourceFactory ¶ added in v0.20.0
func NewSourceFactory() ISourceFactory
NewSourceFactory will instantiate a new source factory instance
type ISourceStrategy ¶
type ISourceStrategy interface { Accept(config IConfig) bool Create(config IConfig) (ISource, error) }
ISourceStrategy interface defines the methods of the source factory strategy that will be used instantiate a particular source type.
type Loader ¶ added in v0.16.0
type Loader struct {
// contains filtered or unexported fields
}
Loader defines an object responsible to initialize a configuration manager.
type Manager ¶ added in v0.16.0
type Manager struct {
// contains filtered or unexported fields
}
Manager defines an object responsible to manage the application several defines sources and config values observers.
func (*Manager) AddObserver ¶ added in v0.16.0
AddObserver register a new observer to a configuration path.
func (*Manager) AddSource ¶ added in v0.16.0
AddSource register a new source with a specific id with a given priority.
func (*Manager) Bool ¶ added in v0.16.0
Bool will retrieve a bool configuration value loaded from a source.
func (*Manager) Close ¶ added in v0.16.0
Close terminates the config instance. This will stop the observer trigger and call close on all registered sources.
func (*Manager) Entries ¶ added in v0.19.0
Entries will retrieve the list of stored entries any registered source.
func (*Manager) Float ¶ added in v0.16.0
Float will retrieve a floating point configuration value loaded from a source.
func (*Manager) Get ¶ added in v0.16.0
Get will retrieve a configuration value loaded from a source.
func (*Manager) Has ¶ added in v0.16.0
Has will check if a path has been loaded. This means that if the values has been loaded by any registered source.
func (*Manager) HasObserver ¶ added in v0.16.0
HasObserver check if there is an observer to a configuration value path.
func (*Manager) HasSource ¶ added in v0.16.0
HasSource check if a source with a specific id has been registered.
func (*Manager) Int ¶ added in v0.16.0
Int will retrieve an integer configuration value loaded from a source.
func (*Manager) List ¶ added in v0.16.0
List will retrieve a list configuration value loaded from a source.
func (*Manager) Populate ¶ added in v0.16.0
Populate will retrieve a config value loaded from a source.
func (*Manager) RemoveAllSources ¶ added in v0.16.0
RemoveAllSources remove all the registered sources from the registration list of the configuration. This will also update the configuration content and re-validate the observed paths.
func (*Manager) RemoveObserver ¶ added in v0.16.0
RemoveObserver remove an observer to a configuration path.
func (*Manager) RemoveSource ¶ added in v0.16.0
RemoveSource remove a source from the registration list of the configuration. This will also update the configuration content and re-validate the observed paths.
func (*Manager) Source ¶ added in v0.16.0
Source retrieve a previously registered source with a requested id.
func (*Manager) SourcePriority ¶ added in v0.16.0
SourcePriority set a priority value of a previously registered source with the specified id. This may change the defined values if there was an override process of the configuration paths of the changing source.
type Provider ¶
type Provider struct{}
Provider defines the slate.config module service provider to be used on the application initialization to register the config service.
type SourceFactory ¶ added in v0.16.0
type SourceFactory []ISourceStrategy
SourceFactory defines an object responsible to instantiate a new config source.
func (*SourceFactory) Create ¶ added in v0.16.0
func (f *SourceFactory) Create( config IConfig, ) (ISource, error)
Create will instantiate and return a new config source where the data used to decide the strategy to be used and also the initialization data comes from a configuration storing Partial instance.
func (*SourceFactory) Register ¶ added in v0.16.0
func (f *SourceFactory) Register( strategy ISourceStrategy, ) error
Register will register a new source factory strategy to be used on creation request.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package decoder defines the base types and structures of all configuration decoding functionalities.
|
Package decoder defines the base types and structures of all configuration decoding functionalities. |
json
Package json defines the JSON format decoder and decoder creation strategy to be integrated into the config package decoder factory instance.
|
Package json defines the JSON format decoder and decoder creation strategy to be integrated into the config package decoder factory instance. |
yaml
Package yaml defines the YAML format decoder and decoder creation strategy to be integrated into the config package decoder factory instance.
|
Package yaml defines the YAML format decoder and decoder creation strategy to be integrated into the config package decoder factory instance. |
Package source defines the base types and structures of all configuration source functionalities.
|
Package source defines the base types and structures of all configuration source functionalities. |
aggregate
Package aggregate defines the aggregate source creation strategy to be integrated into the config package source factory instance.
|
Package aggregate defines the aggregate source creation strategy to be integrated into the config package source factory instance. |
dir
Package dir defines the directory source creation strategy to be integrated into the config package source factory instance.
|
Package dir defines the directory source creation strategy to be integrated into the config package source factory instance. |
env
Package env defines the environment source creation strategy to be integrated into the config package source factory instance.
|
Package env defines the environment source creation strategy to be integrated into the config package source factory instance. |
file
Package file defines the file type sources creation strategies to be integrated into the config package source factory instance.
|
Package file defines the file type sources creation strategies to be integrated into the config package source factory instance. |
rest
Package rest defines the REST connection source creation strategy to be integrated into the config package source factory instance.
|
Package rest defines the REST connection source creation strategy to be integrated into the config package source factory instance. |