xenv

package
v0.2.55 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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 Exist

func Exist(e ...string) bool

Exist check if the environment variable is defined

func ExpandEnv

func ExpandEnv(value string) string

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

func ExpandEnvMap(m map[string]interface{}) map[string]interface{}

ExpandEnvMap Expand env map

func GetEnv

func GetEnv(e ...string) string

GetEnv get environment variable with prefix

func IsDebug

func IsDebug() bool

IsDebug 是否是debug模式

func IsDev

func IsDev() bool

IsDev 是否是dev模式

func IsProd

func IsProd() bool

IsProd 是否是prod模式

func IsRelease

func IsRelease() bool

IsRelease 是否是release模式

func IsSkipXerror

func IsSkipXerror() bool

IsSkipXerror skip xerror file

func IsStag

func IsStag() bool

IsStag 是否是stag模式

func IsTest

func IsTest() bool

IsTest 是否是test模式

func IsTrue

func IsTrue(data string) bool

IsTrue true

func IsVersion

func IsVersion() bool

IsVersion 是否打印项目或者类库的版本信息

func LoadFile

func LoadFile(envFiles ...string) (err error)

LoadFile 加载.env文件并添加前缀

func Log

func Log(filterPrefix ...bool)

Log env log

func ParseToMap

func ParseToMap(filterPrefix ...bool) map[string]string

ParseToMap 解析envs map[string]string

func SetDebug

func SetDebug() (err error)

SetDebug 设置debug模式

func SetDebugFalse

func SetDebugFalse() (err error)

SetDebugFalse 设置debug=false模式

func SetEnv

func SetEnv(e, v string) error

SetEnv set environment variable with prefix

func SetSkipXerror

func SetSkipXerror() (err error)

SetSkipXerror 设置跳过xerror错误打印

func SetVersion

func SetVersion() (err error)

SetVersion 开启打印版本信息环境变量

Types

This section is empty.

Jump to

Keyboard shortcuts

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