vxconf

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(cfg interface{}, path string) (interface{}, error)

Get returns a child of the given value according to a dotted path.

func GetBoolR

func GetBoolR(key string, defaultValue bool) (ret bool)

GetBoolR returns the cmdr value or defaultValue Deprecated

func GetBoolRP

func GetBoolRP(prefix, key string, defaultValue bool) (ret bool)

GetBoolRP returns the cmdr value Deprecated

func GetDurationR

func GetDurationR(key string, defaultValue time.Duration) (ret time.Duration)

GetDurationR returns the cmdr value or defaultValue Deprecated

func GetIntR

func GetIntR(key string, defaultValue int) (ret int)

GetIntR returns the cmdr value or defaultValue Deprecated

func GetMapR

func GetMapR(key string, defaultValue map[string]interface{}) (ret map[string]interface{})

GetMapR returns the cmdr value or defaultValue Deprecated

func GetR

func GetR(key string) (ret interface{})

GetR returns the cmdr value Deprecated

func GetStringR

func GetStringR(key, defaultValue string) (ret string)

GetStringR returns the cmdr value or defaultValue Deprecated

func GetStringRP

func GetStringRP(prefix, key, defaultValue string) (ret string)

GetStringRP returns the cmdr value or defaultValue Deprecated

func GetStringSliceR

func GetStringSliceR(key string, defaultValue []string) (ret []string)

GetStringSliceR returns the cmdr value or defaultValue Deprecated

func IfInt

func IfInt(condition bool, valueIfTrue, valueIfFalse int) int

func IfStr

func IfStr(condition bool, valueIfTrue, valueIfFalse string) string

func IsProd

func IsProd() bool

IsProd return true if app is in production mode.

func JSONToString

func JSONToString(in interface{}, pretty bool) string

JSONToString transforms [in] to json string

func LoadSectionTo

func LoadSectionTo(sectionKeyPath string, configHolder interface{}) (err error)

LoadSectionTo returns error while cannot yaml Marshal and Unmarshal

func RenderJSON

func RenderJSON(cfg interface{}) (string, error)

RenderJSON renders a JSON configuration.

func RenderYaml

func RenderYaml(cfg interface{}) (string, error)

RenderYaml renders a YAML configuration.

func RunMode

func RunMode() string

RunMode returns the running mode: devel, prod, ...

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

func Set(cfg interface{}, path string, value interface{}) error

Set returns an error, in case when it is not possible to establish the value obtained in accordance with given dotted path.

func StringToBool

func StringToBool(s string) (ret bool)

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

func UnescapeUnicode(b []byte) string

UnescapeUnicode 解码 \uxxxx 为 unicode 字符; 但是输入的 b 应该是 yaml 格式

func YamlToString

func YamlToString(in interface{}, pretty bool) string

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

func Must(cfg *AppConfig, err error) *AppConfig

Must is a wrapper for parsing functions to be used during initialization. It panics on failure.

func New

func New() AppConfig

New returns an empty AppConfig instance

func ParseJSON

func ParseJSON(cfg string) (*AppConfig, error)

ParseJSON reads a JSON configuration from the given string.

func ParseJSONFile

func ParseJSONFile(filename string) (*AppConfig, error)

ParseJSONFile reads a JSON configuration from the given filename.

func ParseYaml

func ParseYaml(cfg string) (*AppConfig, error)

ParseYaml reads a YAML configuration from the given string.

func ParseYamlFile

func ParseYamlFile(filename string) (*AppConfig, error)

ParseYamlFile reads a YAML configuration from the given filename.

func (*AppConfig) Bool

func (c *AppConfig) Bool(path string) (bool, error)

Bool returns a bool according to a dotted path.

func (*AppConfig) Copy

func (c *AppConfig) Copy(dottedPath ...string) (*AppConfig, error)

Copy returns a deep copy with given path or without.

func (*AppConfig) Env

func (c *AppConfig) Env() *AppConfig

Env fetches data from system env, based on existing config keys.

func (*AppConfig) EnvPrefix

func (c *AppConfig) EnvPrefix(prefix string) *AppConfig

EnvPrefix fetches data from system env using prefix, based on existing config keys.

func (*AppConfig) Extend

func (c *AppConfig) Extend(cfg *AppConfig) (*AppConfig, error)

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

func (c *AppConfig) Flag() *AppConfig

Flag holds the parseed command line arguments, based on existing config keys.

func (*AppConfig) Float64

func (c *AppConfig) Float64(path string) (float64, error)

Float64 returns a float64 according to a dotted path.

func (*AppConfig) Get

func (c *AppConfig) Get(path string) (*AppConfig, error)

Get returns a nested config according to a dotted path.

func (*AppConfig) Int

func (c *AppConfig) Int(path string) (int, error)

Int returns an int according to a dotted path.

func (*AppConfig) List

func (c *AppConfig) List(path string) ([]interface{}, error)

List returns a []interface{} according to a dotted path.

func (*AppConfig) Map

func (c *AppConfig) Map(path string) (map[string]interface{}, error)

Map returns a map[string]interface{} according to a dotted path.

func (*AppConfig) Set

func (c *AppConfig) Set(path string, val interface{}) error

Set a nested config according to a dotted path.

func (*AppConfig) String

func (c *AppConfig) String(path string) (string, error)

String returns a string according to a dotted path.

func (*AppConfig) UBool

func (c *AppConfig) UBool(path string, defaults ...bool) bool

UBool returns a bool according to a dotted path or default value or false.

func (*AppConfig) UFloat64

func (c *AppConfig) UFloat64(path string, defaults ...float64) float64

UFloat64 returns a float64 according to a dotted path or default value or 0.

func (*AppConfig) UInt

func (c *AppConfig) UInt(path string, defaults ...int) int

UInt returns an int according to a dotted path or default value or 0.

func (*AppConfig) UList

func (c *AppConfig) UList(path string, defaults ...[]interface{}) []interface{}

UList returns a []interface{} according to a dotted path or defaults or []interface{}.

func (*AppConfig) UMap

func (c *AppConfig) UMap(path string, defaults ...map[string]interface{}) map[string]interface{}

UMap returns a map[string]interface{} according to a dotted path or default or map[string]interface{}.

func (*AppConfig) UString

func (c *AppConfig) UString(path string, defaults ...string) string

UString returns a string according to a dotted path or default or "".

type KVStore

type KVStore map[string]string

KVStore is a container

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL