envs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const EnvPrefixSeparator = "_"

Variables

View Source
var Cfg = struct {
	Prefix string
	Env    string
}{
	Prefix: "",
	Env:    RunMode.Dev,
}

Cfg default config

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",
}

Env env配置

Functions

func Exist added in v0.1.27

func Exist(e ...string) bool

Exist check if the environment variable is defined

func ExpandValueEnv added in v0.1.10

func ExpandValueEnv(value string) (realValue string)

ExpandValueEnv 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 ExpandValueEnvForMap added in v0.1.10

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

ExpandValueEnvForMap convert all string value with environment variable.

func GetEnv added in v0.1.1

func GetEnv(e ...string) string

GetEnv get environment variable with prefix

func Init added in v0.1.1

func Init() (err error)

Init init environment

func IsDebug

func IsDebug() bool

IsDebug 是否是debug模式

func IsDev added in v0.1.1

func IsDev() bool

IsDev 是否是dev模式

func IsProd added in v0.1.1

func IsProd() bool

IsProd 是否是prod模式

func IsRelease added in v0.1.27

func IsRelease() bool

IsRelease 是否是release模式

func IsStag added in v0.1.1

func IsStag() bool

IsStag 是否是stag模式

func IsTest added in v0.1.27

func IsTest() bool

IsTest 是否是test模式

func LoadFile added in v0.0.2

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

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

func Parse added in v0.0.2

func Parse() map[string]string

Parse 解析envs map[string]string

func SetDebug

func SetDebug() (err error)

SetDebug 设置debug模式

func SetDebugFalse added in v0.1.27

func SetDebugFalse() (err error)

SetDebugFalse 设置debug=false模式

func SetEnv added in v0.1.0

func SetEnv(e, v string) error

SetEnv set environment variable with prefix

func SetSkipErrorFile

func SetSkipErrorFile() (err error)

SetSkipErrorFile 设置跳过错误

Types

This section is empty.

Jump to

Keyboard shortcuts

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