xenv

package
v0.2.47 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// EnvPrefixSeparator 项目环境变量分隔符
	EnvPrefixSeparator = "_"
	// DefaultEnvPrefix 项目默认环境变量前缀
	DefaultEnvPrefix = "ggg"
	// DefaultEnvPrefixKey 项目默认环境变量名字
	DefaultEnvPrefixKey = "env_prefix"
	// AppSecretKey 项目应用密码名字
	AppSecretKey = "app_secret"
)

Variables

View Source
var Cfg = struct {
	Prefix   string
	Service  string
	Version  string
	Env      string
	Debug    bool
	Home     string
	LogLevel string
}{
	Prefix:   trim(os.Getenv(DefaultEnvPrefixKey)),
	Service:  trim(os.Getenv(DefaultEnvPrefixKey)),
	Version:  "v0.0.1",
	Env:      RunMode.Dev,
	Debug:    true,
	Home:     os.ExpandEnv("$PWD"),
	LogLevel: "debug",
}

Cfg 默认配置

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 added in v0.2.8

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 added in v0.2.8

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

ExpandEnvMap convert all string value with environment variable.

func GetEnv

func GetEnv(e ...string) string

GetEnv get environment variable with prefix

func GetSystemEnv added in v0.2.25

func GetSystemEnv(e ...string) string

GetSystemEnv get system environment

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 IsSkipErrorFile added in v0.2.14

func IsSkipErrorFile() bool

IsSkipErrorFile skip xerror file

func IsStag

func IsStag() bool

IsStag 是否是stag模式

func IsTest

func IsTest() bool

IsTest 是否是test模式

func IsTrue added in v0.2.25

func IsTrue(data string) bool

IsTrue true

func IsVersion added in v0.2.25

func IsVersion() bool

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

func LoadFile

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

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

func Log added in v0.2.25

func Log(filter ...interface{})

Log env log

func ParseToMap added in v0.2.25

func ParseToMap(filter ...interface{}) 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 SetSkipErrorFile

func SetSkipErrorFile() (err error)

SetSkipErrorFile 设置跳过xerror错误打印

func SetSystemEnv added in v0.2.25

func SetSystemEnv(e, v string) error

SetSystemEnv set system environment variable

func SetVersion added in v0.2.25

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