Documentation
¶
Index ¶
- Constants
- Variables
- func Exist(e ...string) bool
- func ExpandEnv(value string) string
- func ExpandEnvMap(m map[string]interface{}) map[string]interface{}
- func GetEnv(e ...string) string
- func IsDebug() bool
- func IsDev() bool
- func IsProd() bool
- func IsRelease() bool
- func IsSkipXerror() bool
- func IsStag() bool
- func IsTest() bool
- func IsTrue(data string) bool
- func IsVersion() bool
- func LoadFile(envFiles ...string) (err error)
- func Log(filterPrefix ...bool)
- func ParseToMap(filterPrefix ...bool) map[string]string
- func SetDebug() (err error)
- func SetDebugFalse() (err error)
- func SetEnv(e, v string) error
- func SetSkipXerror() (err error)
- func SetVersion() (err error)
Constants ¶
View Source
const ( // DefaultPrefixSeparator 项目环境变量默认分隔符 DefaultPrefixSeparator = '_' // DefaultPrefix 项目环境变量默认前缀 DefaultPrefix = "ggg" // DefaultSecret 项目应用默认密码 DefaultSecret = "zpCjWPsbqK@@^hR01qLDmZcXhKRIZgjHfxSG2KA%J#bFp!7YQVSmzXGc!sE!^qSM7@&d%oXHQtpR7K*8eRTdhRKjaxF#t@bd#A!" )
Variables ¶
View Source
var Cfg = struct { Prefix string Env string Debug bool Home string LogLevel string }{ Prefix: func() string { DefaultPrefixKey := xtp.StrOf( "prefix", "app_prefix", "app.prefix", "app-prefix", "env_prefix", "env.prefix", "env-prefix", "prefix_name", "prefix.name", "prefix-name", "server_prefix", "server.prefix", "server-prefix", ) for _, _e := range DefaultPrefixKey { if _v := os.Getenv(_e); _v != "" { return _v } } return "" }(), Env: RunMode.Dev, Debug: false, Home: os.ExpandEnv("$PWD"), LogLevel: "debug", }
Cfg 默认配置
View Source
var ( // DefaultSecretKey 项目应用默认密码名字 DefaultSecretKey = xtp.StrOf( "secret", "token", "app_secret", "app.secret", "app_token", "app.token") )
View Source
var RunMode = struct { Dev string Test string Stag string Prod string Release string }{ Dev: "dev", Test: "test", Stag: "stag", Prod: "prod", Release: "release", }
RunMode 项目运行模式
Functions ¶
func ExpandEnv ¶
ExpandEnv returns value of convert with environment variable. Return environment variable if value start with "${" and end with "}". Return default value if environment variable is empty or not exist.
It accept value formats "${env}" , "${env||}}" , "${env||defaultValue}" , "defaultvalue". Examples:
v1 := config.ExpandValueEnv("${GOPATH}") // return the GOPATH environment variable.
v2 := config.ExpandValueEnv("${GOAsta||/usr/local/go}") // return the default value "/usr/local/go/".
v3 := config.ExpandValueEnv("Astaxie") // return the value "Astaxie".
func ExpandEnvMap ¶
ExpandEnvMap Expand env map
func ParseToMap ¶
ParseToMap 解析envs map[string]string
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.