Documentation ¶
Overview ¶
Package config is nice and handy layer built around `forge` config syntax; which is similar to HOCON syntax. Internally `aah/config` uses `forge` syntax developed by `https://github.com/brettlangdon`.
aah framework is powered with `aahframework.org/config` library.
Index ¶
- type Config
- func (c *Config) Bool(key string) (bool, bool)
- func (c *Config) BoolDefault(key string, defaultValue bool) bool
- func (c *Config) ClearProfile()
- func (c *Config) Float32(key string) (float32, bool)
- func (c *Config) Float32Default(key string, defaultValue float32) float32
- func (c *Config) Float64(key string) (float64, bool)
- func (c *Config) Get(key string) (interface{}, bool)
- func (c *Config) GetSubConfig(key string) (*Config, bool)
- func (c *Config) HasProfile(profile string) bool
- func (c *Config) Int(key string) (int, bool)
- func (c *Config) Int64(key string) (int64, bool)
- func (c *Config) Int64List(key string) ([]int64, bool)
- func (c *Config) IntDefault(key string, defaultValue int) int
- func (c *Config) IntList(key string) ([]int, bool)
- func (c *Config) IsExists(key string) bool
- func (c *Config) IsProfileEnabled() bool
- func (c *Config) Keys() []string
- func (c *Config) KeysByPath(path string) []string
- func (c *Config) Merge(source *Config) error
- func (c *Config) Merge2Section(key string, source *Config) error
- func (c *Config) Profile() string
- func (c *Config) SetBool(key string, value bool)
- func (c *Config) SetFloat32(key string, value float32)
- func (c *Config) SetFloat64(key string, value float64)
- func (c *Config) SetInt(key string, value int)
- func (c *Config) SetInt64(key string, value int64)
- func (c *Config) SetProfile(profile string) error
- func (c *Config) SetString(key string, value string)
- func (c *Config) String(key string) (string, bool)
- func (c *Config) StringDefault(key, defaultValue string) string
- func (c *Config) StringList(key string) ([]string, bool)
- func (c *Config) ToJSON() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config handles the configuration values and enables environment profile's, merge, etc. Also it provide nice and handly methods for accessing config values. Internally `aah config` uses `forge syntax` developed by `https://github.com/brettlangdon`.
func LoadFiles ¶
LoadFiles loads the configuration from given config files. It does merging of configuration in the order they are given.
func ParseString ¶
ParseString parses the configuration values from string
func (*Config) BoolDefault ¶
BoolDefault gets the `bool` value for the given key from the configuration. If key does not exists it returns default value.
func (*Config) ClearProfile ¶
func (c *Config) ClearProfile()
ClearProfile clears currently active configuration `Profile`
func (*Config) Float32Default ¶
Float32Default gets the `float32` value for the given key from the configuration. If key does not exists it returns default value.
func (*Config) Get ¶
Get gets the value from configuration returns as `interface{}`. First it tries to get value within enabled profile otherwise it tries without profile
func (*Config) GetSubConfig ¶
GetSubConfig create new sub config from the given key path. Only `Section` type can be created as sub config. Profile value is not propagated to sub config.
func (*Config) HasProfile ¶
HasProfile checks given configuration profile is exists or not
func (*Config) Int64List ¶
Int64List method returns the int64 slice value for the given key.
Eaxmple:- Config: ... int64_list = [100000001, 100000002, 100000003, 100000004, 100000005] ... Accessing Values: values, found := cfg.Int64List("excludes") fmt.Println("Found:", found) fmt.Println("Values:", values) Output: Found: true Values: [100000001, 100000002, 100000003, 100000004, 100000005]
func (*Config) IntDefault ¶
IntDefault gets the `int` value for the given key from the configuration. If key does not exists it returns default value.
func (*Config) IntList ¶
IntList method returns the int slice value for the given key.
Eaxmple:- Config: ... int_list = [10, 20, 30, 40, 50] ... Accessing Values: values, found := cfg.IntList("int_list") fmt.Println("Found:", found) fmt.Println("Values:", values) Output: Found: true Values: [10, 20, 30, 40, 50]
func (*Config) IsExists ¶
IsExists returns true if given is exists in the config otherwise returns false
func (*Config) IsProfileEnabled ¶
IsProfileEnabled returns true of profile enabled otherwise false
func (*Config) KeysByPath ¶
KeysByPath is similar to `Config.Keys()`, however it returns key names for given key path.
func (*Config) Merge ¶
Merge merges the given section to current section. Settings from source section overwites the values in the current section
NOTE: It does not affect physical config file.
func (*Config) Merge2Section ¶
Merge2Section method allows to merge config into existing config section. Source config becomes child of target section config.
NOTE: It does not affect physical config file.
func (*Config) SetBool ¶
SetBool sets the given value bool for config key First it tries to get value within enabled profile otherwise it tries without profile
func (*Config) SetFloat32 ¶
SetFloat32 sets the given value float32 for config key First it tries to get value within enabled profile otherwise it tries without profile
func (*Config) SetFloat64 ¶
SetFloat64 sets the given value float64 for config key First it tries to get value within enabled profile otherwise it tries without profile
func (*Config) SetInt ¶
SetInt sets the given value int for config key First it tries to get value within enabled profile otherwise it tries without profile
func (*Config) SetInt64 ¶
SetInt64 sets the given value int64 for config key First it tries to get value within enabled profile otherwise it tries without profile
func (*Config) SetProfile ¶
SetProfile actives the configuarion profile if found otherwise returns error
func (*Config) SetString ¶
SetString sets the given value string for config key First it tries to get value within enabled profile otherwise it tries without profile
func (*Config) StringDefault ¶
StringDefault gets the `string` value for the given key from the configuration. If key does not exists it returns default value.
func (*Config) StringList ¶
StringList method returns the string slice value for the given key.
Eaxmple:- Config: ... excludes = ["*_test.go", ".*", "*.bak", "*.tmp", "vendor"] ... Accessing Values: values, found := cfg.StringList("excludes") fmt.Println("Found:", found) fmt.Println("Values:", strings.Join(values, ", ")) Output: Found: true Values: *_test.go, .*, *.bak, *.tmp, vendor