Documentation
¶
Index ¶
Constants ¶
const ( // SourceTypeFile defines the value to be used to declare a // simple file config source type. SourceTypeFile = "file" // SourceTypeObservableFile defines the value to be used to declare a // observable file config source type. SourceTypeObservableFile = "observable_file" // SourceTypeEnv defines the value to be used to declare a // environment config source type. SourceTypeEnv = "env" // DecoderFormatYAML defines the value to be used to declare a YAML // config source format. DecoderFormatYAML = "yaml" // ContainerID defines the id to be used as the default of a // config instance in the application container. ContainerID = "gapp.config" // ContainerSourceStrategyFileID defines the id to be used as // the default of a config file source factory strategy instance in the // application container. ContainerSourceStrategyFileID = ContainerID + ".source.strategy.file" // ContainerSourceStrategyObservableFileID defines the id to // the default of a config observable file source factory strategy instance // in the application container. ContainerSourceStrategyObservableFileID = ContainerID + ".source.strategy.observable_file" // ContainerSourceStrategyEnvironmentID defines the id to the default // of a config environment source factory strategy instance in the // application container. ContainerSourceStrategyEnvironmentID = ContainerID + ".source.strategy.environment" // ContainerSourceFactoryID defines the id to be used as the default // of a config source factory instance in the application container. ContainerSourceFactoryID = ContainerID + ".source.factory" // ContainerDecoderStrategyYamlID defines the id to be used // as the default of a yaml config decoder factory strategy instance in // the application container. ContainerDecoderStrategyYamlID = ContainerID + ".decoder.strategy.yaml" // ContainerDecoderFactoryID defines the id to be used as the // default of a config decoder factory instance in the application // container. ContainerDecoderFactoryID = ContainerID + ".decoder.factory" // ContainerLoaderID defines the id to be used as the default of a // config loader instance in the application container. ContainerLoaderID = ContainerID + ".loader" // EnvObserveFrequency defines the name of the environment variable // to be checked for a overriding value for the config observe frequency. EnvObserveFrequency = "GAPP_CONFIG_OBSERVE_FREQUENCY" // EnvEntrySourceActive defines the name of the environment variable // to be checked for a overriding value for the config entry source active. EnvEntrySourceActive = "GAPP_CONFIG_ENTRY_SOURCE_ACTIVE" // EnvEntrySourceID defines the name of the environment variable // to be checked for a overriding value for the config entry source id. EnvEntrySourceID = "GAPP_CONFIG_ENTRY_SOURCE_ID" // EnvEntrySourcePath defines the name of the environment variable // to be checked for a overriding value for the config entry source path. EnvEntrySourcePath = "GAPP_CONFIG_ENTRY_SOURCE_PATH" // EnvEntrySourceFormat defines the name of the environment variable // to be checked for a overriding value for the config entry source format. EnvEntrySourceFormat = "GAPP_CONFIG_ENTRY_SOURCE_FORMAT" )
Variables ¶
var ( // ObserveFrequency defines the id to be used as the default of a // config observable source frequency time. ObserveFrequency = time.Second * 0 // EntrySourceActive defines the entry config source active flag // used to signal the config loader to load the entry source or not EntrySourceActive = true // EntrySourceID defines the id to be used as the default of the // entry config source id to be used as the loader entry. EntrySourceID = "entry" // EntrySourcePath defines the entry config source path // to be used as the loader entry. EntrySourcePath = "config/config.yaml" // EntrySourceFormat defines the entry config source format // to be used as the loader entry. EntrySourceFormat = DecoderFormatYAML )
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 {
Close()
Has(path string) bool
Get(path string, def ...interface{}) interface{}
GetBool(path string, def ...bool) bool
GetInt(path string, def ...int) int
GetInt8(path string, def ...int8) int8
GetInt16(path string, def ...int16) int16
GetInt32(path string, def ...int32) int32
GetInt64(path string, def ...int64) int64
GetUInt(path string, def ...uint) uint
GetUInt8(path string, def ...uint8) uint8
GetUInt16(path string, def ...uint16) uint16
GetUInt32(path string, def ...uint32) uint32
GetUInt64(path string, def ...uint64) uint64
GetFloat32(path string, def ...float32) float32
GetFloat64(path string, def ...float64) float64
GetComplex64(path string, def ...complex64) complex64
GetComplex128(path string, def ...complex128) complex128
GetRune(path string, def ...rune) rune
GetString(path string, def ...string) string
HasSource(id string) bool
AddSource(id string, priority int, src Source) error
RemoveSource(id string)
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 ¶
type Decoder interface {
Close()
Decode() (partial, error)
}
Decoder interface defines the interaction methods to a config content decoder used to parse the source content into a 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 stream 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 NewDecoderStrategyYaml ¶
func NewDecoderStrategyYaml() DecoderStrategy
NewDecoderStrategyYaml 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 a observed configuration path has changed.
type Partial ¶
type Partial interface {
Has(path string) bool
Get(path string, def ...interface{}) interface{}
Int(path string, def ...int) int
String(path string, def ...string) string
Config(path string, def ...Partial) Partial
}
Partial defined a type used to store configuration information.
func NewPartial ¶ added in v1.1.0
func NewPartial(data map[interface{}]interface{}) Partial
NewPartial is a function that will instantiate a new configuration partial instance, initialized with the assigned mappings/values
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, error)
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
- decoder_strategy_yaml.go
- decoder_yaml.go
- env_source.go
- env_source_strategy.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