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) AddObserver(path string, callback Observer) error
- func (c *Config) AddSource(id string, priority int, src Source) error
- func (c *Config) Bool(path string, def ...bool) (bool, error)
- func (c *Config) Close() 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) HasObserver(path string) bool
- func (c *Config) HasSource(id 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) Partial(path string, def ...Partial) (Partial, error)
- func (c *Config) Populate(path string, data interface{}, icase ...bool) (interface{}, error)
- func (c *Config) RemoveAllSources() error
- func (c *Config) RemoveObserver(path string)
- func (c *Config) RemoveSource(id string) error
- func (c *Config) Source(id string) (Source, error)
- func (c *Config) SourcePriority(id string, priority int) error
- func (c *Config) String(path string, def ...string) (string, error)
- type Decoder
- type DecoderFactory
- type DecoderStrategy
- type Loader
- type ObsSource
- type Observer
- type Partial
- func (p *Partial) Bool(path string, def ...bool) (bool, error)
- func (p *Partial) Clone() Partial
- func (p *Partial) Entries() []string
- func (p *Partial) Float(path string, def ...float64) (float64, error)
- func (p *Partial) Get(path string, def ...interface{}) (interface{}, error)
- func (p *Partial) Has(path string) bool
- func (p *Partial) Int(path string, def ...int) (int, error)
- func (p *Partial) List(path string, def ...[]interface{}) ([]interface{}, error)
- func (p *Partial) Merge(src Partial)
- func (p *Partial) Partial(path string, def ...Partial) (Partial, error)
- func (p *Partial) Populate(path string, data interface{}, icase ...bool) (interface{}, error)
- func (p *Partial) Set(path string, value interface{}) (*Partial, error)
- func (p *Partial) String(path string, def ...string) (string, error)
- type Provider
- type Source
- type SourceFactory
- type SourceStrategy
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 observer instance. LoaderID = ID + ".observer" )
const ( // EnvID defines the slate.config package base environment variable name. EnvID = slate.EnvID + "_CONFIG" )
const ( // UnknownDecoder defines the value to be used to // declare an unknown partial source format. UnknownDecoder = "unknown" )
const ( // UnknownSource defines the value to be used to declare an // unknown partial source type. UnknownSource = "unknown" )
Variables ¶
var ( // DefaultFileFormat defines the file base config source simple // 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 simple // 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 observer should be executed // while the provider boot LoaderActive = env.Bool(EnvID+"_LOADER_ACTIVE", true) // LoaderSourceID defines the id to be used as the simple of the // entry config source id to be used as the observer entry. LoaderSourceID = env.String(EnvID+"_LOADER_SOURCE_ID", "_sources") // LoaderSourcePath defines the entry config source path // to be used as the observer entry. LoaderSourcePath = env.String(EnvID+"_LOADER_SOURCE_PATH", "config/sources.yaml") // LoaderSourceFormat defines the entry config source format // to be used as the observer 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 simple of a // config observable source frequency time in seconds. ObserveFrequency = env.Int(EnvID+"_OBSERVE_FREQUENCY", 0) )
var ( // ErrInvalidEmptyPath defines an invalid empty path in Partial // assigning error. ErrInvalidEmptyPath = fmt.Errorf("invalid empty config path") // ErrPathNotFound defines a path in Partial 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 struct {
// contains filtered or unexported fields
}
Config defines an object responsible to config the application several defines sources and partial values observers.
func NewConfig ¶ added in v0.23.0
func NewConfig() *Config
NewConfig instantiate a new configuration object. This object will config 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.
func (*Config) AddObserver ¶ added in v0.23.0
AddObserver register a new observer to a configuration path.
func (*Config) AddSource ¶ added in v0.23.0
AddSource register a new source with a specific id with a given priority.
func (*Config) Bool ¶ added in v0.16.0
Bool will retrieve a bool configuration value loaded from a source.
func (*Config) Close ¶ added in v0.23.0
Close terminates the config instance. This will stop the observer trigger and call close on all registered sources.
func (*Config) Entries ¶ added in v0.19.0
Entries will retrieve the list of stored entries any registered source.
func (*Config) Float ¶ added in v0.16.0
Float will retrieve a floating point configuration value loaded from a source.
func (*Config) 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 (*Config) HasObserver ¶ added in v0.23.0
HasObserver check if there is an observer to a configuration value path.
func (*Config) HasSource ¶ added in v0.23.0
HasSource check if a source with a specific id has been registered.
func (*Config) Int ¶ added in v0.16.0
Int will retrieve an integer configuration value loaded from a source.
func (*Config) List ¶ added in v0.16.0
List will retrieve a list configuration value loaded from a source.
func (*Config) Partial ¶ added in v0.23.0
Partial will retrieve partial values loaded from a source.
func (*Config) Populate ¶ added in v0.16.0
Populate will retrieve a config value loaded from a source.
func (*Config) RemoveAllSources ¶ added in v0.23.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 (*Config) RemoveObserver ¶ added in v0.23.0
RemoveObserver remove an observer to a configuration path.
func (*Config) RemoveSource ¶ added in v0.23.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 (*Config) Source ¶ added in v0.23.0
Source retrieve a previously registered source with a requested id.
func (*Config) SourcePriority ¶ added in v0.23.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 Decoder ¶ added in v0.23.0
Decoder interface defines the interaction methods to a partial content decoder used to parse the source content into an application usable configuration Partial instance.
type DecoderFactory ¶ added in v0.16.0
type DecoderFactory []DecoderStrategy
DecoderFactory defines a decoder instantiation factory.
func NewDecoderFactory ¶ added in v0.20.0
func NewDecoderFactory() *DecoderFactory
NewDecoderFactory will instantiate a new decoder factory instance.
func (*DecoderFactory) Create ¶ added in v0.16.0
func (f *DecoderFactory) Create( format string, args ...interface{}, ) (Decoder, 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 DecoderStrategy, ) 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 DecoderStrategy ¶ added in v0.23.0
type DecoderStrategy interface { Accept(format string) bool Create(args ...interface{}) (Decoder, error) }
DecoderStrategy interface defines the methods of the decoder factory strategy that can validate creation requests and instantiation of a particular decoder.
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 ObsSource ¶ added in v0.23.0
ObsSource interface extends the Source 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 Observer ¶ added in v0.23.0
type Observer func(interface{}, interface{})
Observer callback function used to be called when an observed configuration path has changed.
type Partial ¶
type Partial map[interface{}]interface{}
Partial defines a section of a configuration information
func (*Partial) Entries ¶ added in v0.23.0
Entries will retrieve the list of stored entries in the configuration.
func (*Partial) Get ¶
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 simple value was given as the optional extra argument, then it will be returned instead of the standard nil value.
func (*Partial) Merge ¶ added in v0.23.0
Merge will increment the current partial instance with the information stored in another partial.
func (*Partial) Populate ¶ added in v0.23.0
Populate will try to populate the data argument with the data stored in the path partial location.
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 Source ¶ added in v0.16.0
type Source interface { Has(path string) bool Get(path string, def ...interface{}) (interface{}, error) }
Source defines the base interface of a partial source.
type SourceFactory ¶ added in v0.16.0
type SourceFactory []SourceStrategy
SourceFactory defines an object responsible to instantiate a new partial source.
func NewSourceFactory ¶ added in v0.20.0
func NewSourceFactory() *SourceFactory
NewSourceFactory will instantiate a new source factory instance
func (*SourceFactory) Create ¶ added in v0.16.0
func (f *SourceFactory) Create( cfg Partial, ) (Source, error)
Create will instantiate and return a new partial 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 SourceStrategy, ) 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. |