Documentation ¶
Index ¶
- type ConfigParams
- func NewConfigParams(values map[string]string) *ConfigParams
- func NewConfigParamsFromMaps(maps ...map[string]string) *ConfigParams
- func NewConfigParamsFromString(line string) *ConfigParams
- func NewConfigParamsFromTuples(tuples ...interface{}) *ConfigParams
- func NewConfigParamsFromTuplesArray(tuples []interface{}) *ConfigParams
- func NewConfigParamsFromValue(value interface{}) *ConfigParams
- func NewEmptyConfigParams() *ConfigParams
- func (c *ConfigParams) AddSection(section string, sectionParams *ConfigParams)
- func (c *ConfigParams) GetSection(section string) *ConfigParams
- func (c *ConfigParams) GetSectionNames() []string
- func (c *ConfigParams) Override(configParams *ConfigParams) *ConfigParams
- func (c *ConfigParams) SetDefaults(defaults *ConfigParams) *ConfigParams
- type IConfigurable
- type IReconfigurable
- type TNameResolver
- type TOptionsResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigParams ¶
type ConfigParams struct {
data.StringValueMap
}
Contains a key-value map with configuration parameters. All values stored as strings and can be serialized as JSON or string forms. When retrieved the values can be automatically converted on read using GetAsXXX methods. The keys are case-sensitive, so it is recommended to use consistent C-style as: "my_param"
Configuration parameters can be broken into sections and subsections using dot notation as: "section1.subsection1.param1". Using GetSection method all parameters from specified section can be extracted from a ConfigMap.
The ConfigParams supports serialization from/to plain strings as: "key1=123;key2=ABC;key3=2016-09-16T00:00:00.00Z"
ConfigParams are used to pass configurations to IConfigurable objects. They also serve as a basis for more concrete configurations such as ConnectionParams or CredentialParams (in the Pip.Services components package).
see IConfigurable
see StringValueMap
Example:
config := NewConfigParamsFromTuples( "section1.key1", "AAA", "section1.key2", 123, "section2.key1", true ); config.GetAsString("section1.key1"); // Result: AAA config.GetAsInteger("section1.key1"); // Result: 0 section1 = config.GetSection("section2"); section1.GetAsString("key1"); // Result: true
func NewConfigParams ¶
func NewConfigParams(values map[string]string) *ConfigParams
Creates a new ConfigParams from map. Parameters:
- values ...map[string]string
Returns *ConfigParams a newly created ConfigParams.
func NewConfigParamsFromMaps ¶
func NewConfigParamsFromMaps(maps ...map[string]string) *ConfigParams
Creates a new ConfigParams by merging two or more maps. Maps defined later in the list override values from previously defined maps. Parameters:
- maps ...map[string]string an array of maps to be merged
Returns *ConfigParams a newly created ConfigParams.
func NewConfigParamsFromString ¶
func NewConfigParamsFromString(line string) *ConfigParams
Creates a new ConfigParams object filled with key-value pairs serialized as a string. see StringValueMap.fromString Parameters:
- line: string a string with serialized key-value pairs as "key1=value1;key2=value2;..." Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"
Returns *ConfigParams a new ConfigParams object.
func NewConfigParamsFromTuples ¶
func NewConfigParamsFromTuples(tuples ...interface{}) *ConfigParams
Returns ConfigParams a new ConfigParams object.
func NewConfigParamsFromTuplesArray ¶
func NewConfigParamsFromTuplesArray(tuples []interface{}) *ConfigParams
Creates a new StringValueMap from a list of key-value pairs called tuples. The method is similar to fromTuples but tuples are passed as array instead of parameters. Parameters:
- tuples []interface{} a list of values where odd elements are keys and the following even elements are values
Returns *ConfigParams a newly created ConfigParams.
func NewConfigParamsFromValue ¶
func NewConfigParamsFromValue(value interface{}) *ConfigParams
Creates a new ConfigParams object filled with key-value pairs from specified object. Parameters:
- value interface{} an object with key-value pairs used to initialize a new ConfigParams.
Returns *ConfigParams a new ConfigParams object.
func NewEmptyConfigParams ¶
func NewEmptyConfigParams() *ConfigParams
Creates a new empty ConfigParams object. Returns *ConfigParams a new empty ConfigParams object.
func (*ConfigParams) AddSection ¶
func (c *ConfigParams) AddSection(section string, sectionParams *ConfigParams)
Adds parameters into this ConfigParams under specified section. Keys for the new parameters are appended with section dot prefix. Parameters:
- section: string name of the section where add new parameters
- sectionParams: *ConfigParams new parameters to be added.
func (*ConfigParams) GetSection ¶
func (c *ConfigParams) GetSection(section string) *ConfigParams
Gets parameters from specific section stored in this ConfigMap. The section name is removed from parameter keys. Parameters:
- section: string name of the section to retrieve configuration parameters from.
Returns *ConfigParams all configuration parameters that belong to the section named 'section'.
func (*ConfigParams) GetSectionNames ¶
func (c *ConfigParams) GetSectionNames() []string
func (*ConfigParams) Override ¶
func (c *ConfigParams) Override(configParams *ConfigParams) *ConfigParams
Overrides parameters with new values from specified ConfigParams and returns a new ConfigParams object. see setDefaults Parameters:
- configParams: *ConfigParams ConfigMap with parameters to override the current values.
Returns *ConfigParams a new ConfigParams object.
func (*ConfigParams) SetDefaults ¶
func (c *ConfigParams) SetDefaults(defaults *ConfigParams) *ConfigParams
Set default values from specified ConfigParams and returns a new ConfigParams object. see override Parameters:
- defaultConfigParams: *ConfigParams ConfigMap with default parameter values.
Returns *ConfigParams a new ConfigParams object.
type IConfigurable ¶
type IConfigurable interface { // Parameters: // - config: ConfigParams // configuration parameters to be set. Configure(config *ConfigParams) }
An interface to set configuration parameters to an object.
It can be added to any existing class by implementing a single configure() method.
If you need to emphasis the fact that configure() method can be called multiple times to change object configuration in runtime, use IReconfigurable interface instead.
type IReconfigurable ¶
type IReconfigurable interface { IConfigurable }
An interface to set configuration parameters to an object.
It is similar to IConfigurable interface, but emphasises the fact that Configure() method can be called more than once to change object configuration in runtime.
type TNameResolver ¶
type TNameResolver struct{}
A helper class that allows to extract component name from configuration parameters. The name can be defined in "id", "name" parameters or inside a component descriptor. Example:
config := NewConfigParamsFromTuples( "descriptor", "myservice:connector:aws:connector1:1.0", "param1", "ABC", "param2", 123 ); name := NameResolver.Resolve(config); // Result: connector1
var NameResolver *TNameResolver = &TNameResolver{}
func (*TNameResolver) Resolve ¶
func (c *TNameResolver) Resolve(config *ConfigParams) string
Resolves a component name from configuration parameters. The name can be stored in "id", "name" fields or inside a component descriptor. If name cannot be determined it returns a empty string. Parameters:
- config: ConfigParams configuration parameters that may contain a component name.
Returns string resolved name or "" if the name cannot be determined.
func (*TNameResolver) ResolveWithDefault ¶
func (c *TNameResolver) ResolveWithDefault(config *ConfigParams, defaultName string) string
Resolves a component name from configuration parameters. The name can be stored in "id", "name" fields or inside a component descriptor. If name cannot be determined it returns a defaultName. Parameters:
- config: ConfigParams configuration parameters that may contain a component name.
- defaultName: string a default component name.
Returns string resolved name or default name if the name cannot be determined.
type TOptionsResolver ¶
type TOptionsResolver struct{}
A helper class to parameters from "options" configuration section.
Example:
config := NewConfigParamsFromTuples( ... "options.param1", "ABC", "options.param2", 123 ); options := OptionsResolver.resolve(config); // Result: param1=ABC;param2=123
var OptionsResolver *TOptionsResolver = &TOptionsResolver{}
func (*TOptionsResolver) Resolve ¶
func (c *TOptionsResolver) Resolve(config *ConfigParams) *ConfigParams
Resolves configuration section from component configuration parameters. Parameters:
- config: ConfigParams configuration parameters
Returns *ConfigParams configuration parameters from "options" section
func (*TOptionsResolver) ResolveWithDefault ¶
func (c *TOptionsResolver) ResolveWithDefault(config *ConfigParams) *ConfigParams
Resolves an "options" configuration section from component configuration parameters. Parameters:
- config: ConfigParams configuration parameters
- configAsDefault: boolean When set true the method returns the entire parameter set when "options" section is not found. Default: false
Returns *ConfigParams configuration parameters from "options" section