Documentation ¶
Index ¶
- Constants
- Variables
- func NewProvider() gapp.Provider
- type Config
- type Decoder
- type DecoderFactory
- type DecoderStrategy
- type Loader
- type ObservableSource
- type Observer
- type Partial
- func (p Partial) Get(path string, def ...interface{}) interface{}
- func (p Partial) Has(path string) bool
- func (p Partial) Int(path string, def ...int) int
- func (p Partial) List(path string, def ...[]interface{}) []interface{}
- func (p Partial) Partial(path string, def ...Partial) Partial
- func (p Partial) String(path string, def ...string) string
- type Source
- type SourceFactory
- type SourceStrategy
Constants ¶
const ( // FileSourceType defines the value to be used to declare a // simple file config source type. FileSourceType = "file" // ObservableFileSourceType defines the value to be used to // declare an observable file config source type. ObservableFileSourceType = "observable_file" // EnvSourceType defines the value to be used to declare an // environment config source type. EnvSourceType = "env" // YamlDecoderFormat defines the value to be used to declare a YAML // config source format. YamlDecoderFormat = "yaml" )
const ( // ContainerID 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. ContainerID = gapp.ContainerID + ".config" // ContainerDecoderStrategyTag defines the tag to be assigned to all // container decoders strategies. ContainerDecoderStrategyTag = ContainerID + ".decoder.strategy" // ContainerYamlDecoderStrategyID defines the id to be used as the // container registration id of a yaml config decoder factory strategy // instance. ContainerYamlDecoderStrategyID = ContainerID + ".decoder.strategy.yaml" // ContainerDecoderFactoryID defines the id to be used as the // container registration id of a config decoder factory instance. ContainerDecoderFactoryID = ContainerID + ".decoder.factory" // ContainerSourceStrategyTag defines the tag to be assigned to all // container source strategies. ContainerSourceStrategyTag = ContainerID + ".source.strategy" // ContainerFileSourceStrategyID defines the id to be used as the // container registration id of a config file source factory strategy // instance. ContainerFileSourceStrategyID = ContainerID + ".source.strategy.file" // ContainerObservableFileSourceStrategyID defines the id to be used // as the container registration id of a config observable file source // factory strategy instance. ContainerObservableFileSourceStrategyID = ContainerID + ".source.strategy.observable_file" // ContainerEnvSourceStrategyID defines the id to be used as // the container registration id of a config environment source // factory strategy instance. ContainerEnvSourceStrategyID = ContainerID + ".source.strategy.environment" // ContainerSourceFactoryID defines the id to be used as the // container registration id config source factory instance. ContainerSourceFactoryID = ContainerID + ".source.factory" // ContainerLoaderID defines the id to be used as the container // registration id of a config loader instance. ContainerLoaderID = ContainerID + ".loader" )
const ( // Env defines the gapp/config package environment entry id base // string. Env = gapp.Env + "_CONFIG" // EnvObserveFrequency defines the name of the environment variable // to be checked for an overriding value for the config observe frequency // in seconds. EnvObserveFrequency = Env + "_OBSERVE_FREQUENCY" // EnvLoaderActive defines the name of the environment variable // to be checked for an overriding value for the config loader // activation. EnvLoaderActive = Env + "_LOADER_ACTIVE" // EnvLoaderSourceID defines the name of the environment variable // to be checked for an overriding value for the config loader entry // source id. EnvLoaderSourceID = Env + "_LOADER_SOURCE_ID" // EnvLoaderSourcePath defines the name of the environment variable // to be checked for an overriding value for the config loader entry // source path. EnvLoaderSourcePath = Env + "_LOADER_SOURCE_PATH" // EnvLoaderSourceFormat defines the name of the environment variable // to be checked for an overriding value for the config loader entry // source format. EnvLoaderSourceFormat = Env + "_LOADER_SOURCE_FORMAT" )
Variables ¶
var ( // ObserveFrequency defines the id to be used as the default of a // config observable source frequency time in seconds. ObserveFrequency = 0 // LoaderActive defines if the config loader should be executed // while the provider boot LoaderActive = true // LoaderSourceID defines the id to be used as the default of the // entry config source id to be used as the loader entry. LoaderSourceID = "main" // LoaderSourcePath defines the entry config source path // to be used as the loader entry. LoaderSourcePath = "config/config.yaml" // LoaderSourceFormat defines the entry config source format // to be used as the loader entry. LoaderSourceFormat = YamlDecoderFormat )
Functions ¶
func NewProvider ¶
NewProvider will create a new configuration provider instance used to register the basic configuration objects in the application container.
Types ¶
type Config ¶
type Config interface { io.Closer Has(path string) bool Get(path string, def ...interface{}) interface{} Bool(path string, def ...bool) bool Int(path string, def ...int) int Int8(path string, def ...int8) int8 Int16(path string, def ...int16) int16 Int32(path string, def ...int32) int32 Int64(path string, def ...int64) int64 UInt(path string, def ...uint) uint UInt8(path string, def ...uint8) uint8 UInt16(path string, def ...uint16) uint16 UInt32(path string, def ...uint32) uint32 UInt64(path string, def ...uint64) uint64 Float32(path string, def ...float32) float32 Float64(path string, def ...float64) float64 Complex64(path string, def ...complex64) complex64 Complex128(path string, def ...complex128) complex128 Rune(path string, def ...rune) rune String(path string, def ...string) string List(path string, def ...[]interface{}) []interface{} Partial(path string, def ...Partial) Partial HasSource(id string) bool AddSource(id string, priority int, src Source) error RemoveSource(id string) error Source(id string) (Source, error) SourcePriority(id string, priority int) error HasObserver(path string) bool AddObserver(path string, callback Observer) error RemoveObserver(path string) }
Config defines the instance of a configuration managing structure.
type Decoder ¶
Decoder interface defines the interaction methods to a config content decoder used to parse the source content into an application usable configuration partial instance.
type DecoderFactory ¶
type DecoderFactory interface { Register(strategy DecoderStrategy) error Create(format string, args ...interface{}) (Decoder, error) }
DecoderFactory defined the instance used to instantiate a new config logStream decoder for a specific encoding format.
func NewDecoderFactory ¶
func NewDecoderFactory() DecoderFactory
NewDecoderFactory instantiate a new decoder factory.
type DecoderStrategy ¶
type DecoderStrategy interface { Accept(format string, args ...interface{}) 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.
func NewYamlDecoderStrategy ¶ added in v1.11.0
func NewYamlDecoderStrategy() DecoderStrategy
NewYamlDecoderStrategy instantiate a new yaml decoder factory strategy that will enable the decoder factory to instantiate a new yaml decoder.
type Loader ¶
Loader defines the config instantiation and initialization of a new config managing structure.
type ObservableSource ¶
ObservableSource 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.
func NewObservableFileSource ¶
func NewObservableFileSource(path string, format string, fs afero.Fs, factory DecoderFactory) (ObservableSource, error)
NewObservableFileSource instantiate a new source that treats a file as the origin of the configuration content. This file source will be periodically checked for changes and loaded if so.
type Observer ¶
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 defined a type used to store configuration information.
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 default value was given as the optional extra argument, then it will be returned instead of the standard nil value.
func (Partial) Int ¶
Int will return the casting to int of the stored value in the requested path. If the value retrieved was not found or returned nil, then the default optional argument will be returned if given.
func (Partial) List ¶ added in v1.11.0
List will return the casting to a list of the stored value in the requested path. If the value retrieved was not found or returned nil, then the default optional argument will be returned if given.
type Source ¶
Source defines the base interface of a config source.
func NewEnvSource ¶
NewEnvSource instantiate a new source that read a list of environment variables into mapped config paths.
func NewFileSource ¶
NewFileSource instantiate a new source that treats a file as the origin of the configuration content.
type SourceFactory ¶
type SourceFactory interface { Register(strategy SourceStrategy) error Create(sourceType string, args ...interface{}) (Source, error) CreateFromConfig(cfg Partial) (Source, error) }
SourceFactory defines a config source factory that uses a list of registered instantiation strategies to perform the config source instantiation.
func NewSourceFactory ¶
func NewSourceFactory() SourceFactory
NewSourceFactory instantiate a new source factory.
type SourceStrategy ¶
type SourceStrategy interface { Accept(sourceType string, args ...interface{}) bool AcceptFromConfig(cfg Partial) bool Create(args ...interface{}) (Source, error) CreateFromConfig(cfg Partial) (Source, error) }
SourceStrategy interface defines the methods of the source factory strategy that will be used instantiate a particular source type.
func NewEnvSourceStrategy ¶
func NewEnvSourceStrategy() SourceStrategy
NewEnvSourceStrategy instantiate a new environment source factory strategy that will enable the source factory to instantiate a new observable file configuration source.
func NewFileSourceStrategy ¶
func NewFileSourceStrategy(fs afero.Fs, factory DecoderFactory) (SourceStrategy, error)
NewFileSourceStrategy instantiate a new file source factory strategy that will enable the source factory to instantiate a new file configuration source.
func NewObservableFileSourceStrategy ¶
func NewObservableFileSourceStrategy(fs afero.Fs, factory DecoderFactory) (SourceStrategy, error)
NewObservableFileSourceStrategy instantiate a new observable file source factory strategy that will enable the source factory to instantiate a new observable file configuration source.
Source Files ¶
- config.go
- decoder.go
- decoder_factory.go
- decoder_strategy.go
- env_source.go
- env_source_strategy.go
- errors.go
- file_source.go
- file_source_strategy.go
- globals.go
- loader.go
- observable_file_source.go
- observable_file_source_strategy.go
- observable_source.go
- observer.go
- partial.go
- provider.go
- source.go
- source_factory.go
- source_strategy.go
- yaml_decoder.go
- yaml_decoder_strategy.go