env

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Home = lavax.FirstNotEmpty(
	homedir.HomeDir,
	func() string {
		var h, err = dir.Dir()
		xerror.Exit(err)
		return h
	},
)

Home the home directory for the current user

View Source
var Hostname = lavax.FirstNotEmpty(
	func() string { return os.Getenv("HOSTNAME") },
	func() string {
		var h, err = os.Hostname()
		xerror.Exit(err)
		return h
	},
)
View Source
var Namespace = lavax.FirstNotEmpty(
	func() string { return os.Getenv("NAMESPACE") },
	func() string { return os.Getenv("POD_NAMESPACE") },
	func() string {
		if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
			if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
				return ns
			}
		}
		return ""
	},
	func() string { return "default" },
)
View Source
var Prefix = os.Getenv(strings.ToUpper("env_prefix"))

Prefix 系统环境变量前缀

Pwd 当前目录

Functions

func Expand

func Expand(value string) string

Expand 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.Expand("${GOPATH}")			// return the GOPATH environment variable.
v2 := config.Expand("${GOPATH||/usr/local/go}")	// return the default value "/usr/local/go/".
v3 := config.Expand("Astaxie")				// return the value "Astaxie".

func Get

func Get(names ...string) string

func GetBoolVal

func GetBoolVal(val *bool, names ...string)

func GetFloatVal

func GetFloatVal(val *float64, names ...string)

func GetIntVal

func GetIntVal(val *int, names ...string)

func GetWith

func GetWith(val *string, names ...string)

func List

func List() map[string]string

func Lookup

func Lookup(key string) (string, bool)

func Set

func Set(key, value string) error

func Unsetenv

func Unsetenv(key string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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