Documentation ¶
Index ¶
- func Get(cfg interface{}, path string) (interface{}, error)
- func GetBoolR(key string, defaultValue bool) (ret bool)
- func GetBoolRP(prefix, key string, defaultValue bool) (ret bool)
- func GetDurationR(key string, defaultValue time.Duration) (ret time.Duration)
- func GetIntR(key string, defaultValue int) (ret int)
- func GetMapR(key string, defaultValue map[string]interface{}) (ret map[string]interface{})
- func GetR(key string) (ret interface{})
- func GetStringR(key, defaultValue string) (ret string)
- func GetStringRP(prefix, key, defaultValue string) (ret string)
- func GetStringSliceR(key string, defaultValue []string) (ret []string)
- func IfInt(condition bool, valueIfTrue, valueIfFalse int) int
- func IfStr(condition bool, valueIfTrue, valueIfFalse string) string
- func IsProd() bool
- func JSONToString(in interface{}, pretty bool) string
- func LoadSectionTo(sectionKeyPath string, configHolder interface{}) (err error)
- func RenderJSON(cfg interface{}) (string, error)
- func RenderYaml(cfg interface{}) (string, error)
- func RunMode() string
- func RunModeExt() string
- func Set(cfg interface{}, path string, value interface{}) error
- func StringToBool(s string) (ret bool)
- func ToBool(s interface{}) (ret bool)
- func UnescapeUnicode(b []byte) string
- func YamlToString(in interface{}, pretty bool) string
- type AppConfig
- func (c *AppConfig) Bool(path string) (bool, error)
- func (c *AppConfig) Copy(dottedPath ...string) (*AppConfig, error)
- func (c *AppConfig) Env() *AppConfig
- func (c *AppConfig) EnvPrefix(prefix string) *AppConfig
- func (c *AppConfig) Extend(cfg *AppConfig) (*AppConfig, error)
- func (c *AppConfig) Flag() *AppConfig
- func (c *AppConfig) Float64(path string) (float64, error)
- func (c *AppConfig) Get(path string) (*AppConfig, error)
- func (c *AppConfig) Int(path string) (int, error)
- func (c *AppConfig) List(path string) ([]interface{}, error)
- func (c *AppConfig) Map(path string) (map[string]interface{}, error)
- func (c *AppConfig) Set(path string, val interface{}) error
- func (c *AppConfig) String(path string) (string, error)
- func (c *AppConfig) UBool(path string, defaults ...bool) bool
- func (c *AppConfig) UFloat64(path string, defaults ...float64) float64
- func (c *AppConfig) UInt(path string, defaults ...int) int
- func (c *AppConfig) UList(path string, defaults ...[]interface{}) []interface{}
- func (c *AppConfig) UMap(path string, defaults ...map[string]interface{}) map[string]interface{}
- func (c *AppConfig) UString(path string, defaults ...string) string
- type KVStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDurationR ¶
GetDurationR returns the cmdr value or defaultValue Deprecated
func GetStringR ¶
GetStringR returns the cmdr value or defaultValue Deprecated
func GetStringRP ¶
GetStringRP returns the cmdr value or defaultValue Deprecated
func GetStringSliceR ¶
GetStringSliceR returns the cmdr value or defaultValue Deprecated
func JSONToString ¶
JSONToString transforms [in] to json string
func LoadSectionTo ¶
LoadSectionTo returns error while cannot yaml Marshal and Unmarshal
func RenderJSON ¶
RenderJSON renders a JSON configuration.
func RenderYaml ¶
RenderYaml renders a YAML configuration.
func RunModeExt ¶
func RunModeExt() string
RunModeExt returns the running mode: devel, prod, ... While env-var 'ENT_POS' exists, it looks like: devel-local, devel-lan, devel, ...
func Set ¶
Set returns an error, in case when it is not possible to establish the value obtained in accordance with given dotted path.
func StringToBool ¶
StringToBool parses the string to bool type. these strings will be scanned as true: "1", "y", "t", "yes", "true", "ok", "on"
func ToBool ¶
func ToBool(s interface{}) (ret bool)
ToBool parses the string to bool type. these strings will be scanned as true: "1", "y", "t", "yes", "true", "ok", "on"
func UnescapeUnicode ¶
UnescapeUnicode 解码 \uxxxx 为 unicode 字符; 但是输入的 b 应该是 yaml 格式
func YamlToString ¶
YamlToString transforms [in] to yaml string
Types ¶
type AppConfig ¶
type AppConfig struct { // Root will be loaded from meta.yaml Root interface{} // KV is a container that holds this app runtime k/v store KV KVStore }
AppConfig represents a configuration with convenient access methods.
func Must ¶
Must is a wrapper for parsing functions to be used during initialization. It panics on failure.
func ParseJSONFile ¶
ParseJSONFile reads a JSON configuration from the given filename.
func ParseYamlFile ¶
ParseYamlFile reads a YAML configuration from the given filename.
func (*AppConfig) EnvPrefix ¶
EnvPrefix fetches data from system env using prefix, based on existing config keys.
func (*AppConfig) Extend ¶
Extend returns extended copy of current config with applied values from the given config instance. Note that if you extend with different structure you will get an error. See: `.Set()` method for details.
func (*AppConfig) Flag ¶
Flag holds the parseed command line arguments, based on existing config keys.
func (*AppConfig) UBool ¶
UBool returns a bool according to a dotted path or default value or false.
func (*AppConfig) UFloat64 ¶
UFloat64 returns a float64 according to a dotted path or default value or 0.
func (*AppConfig) UList ¶
UList returns a []interface{} according to a dotted path or defaults or []interface{}.