env

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RegexEnvVar = regexp.MustCompile(`\$([a-zA-Z_][a-zA-Z0-9_]*)|\$\{([a-zA-Z_][a-zA-Z0-9_]*)(:-([^}]*))?\}`)
)

Functions

func ExpandEnvVar added in v1.1.0

func ExpandEnvVar(s string) (string, error)

func ExpandEnvVars

func ExpandEnvVars(s interface{})

ExpandEnvVars expands environment variables in a struct recusively. It expands the string fields in the struct and its sub-structs including a map with string values.

func Get

func Get(key string, def string) string

Get returns an env with a given key and returns `def` if its empty.

func GetInt

func GetInt(key string, def int) int

GetInt returns an int value of an env variable.

func IsSet

func IsSet(key string) bool

IsSet returns a bool value of an env variable.

func ReplaceEnvVars added in v1.1.0

func ReplaceEnvVars(s string, refs []EnvVarRef, em EnvMap) string

Types

type EnvMap

type EnvMap map[string]string

func (EnvMap) AsString

func (em EnvMap) AsString() (ret []string)

AsString returns a list of KEY=VALUE strings.

func (EnvMap) Expand

func (em EnvMap) Expand(t interface{})

Expand recursively expands string files from a struct.

func (EnvMap) Load

func (em EnvMap) Load(envs []string)

Load loads envs from a string array

func (EnvMap) LoadFile

func (em EnvMap) LoadFile(f ...string)

LoadFile load env files

func (EnvMap) LoadSystem

func (em EnvMap) LoadSystem()

LoadSystem loads os.Environ() into this map

func (EnvMap) Merge

func (em EnvMap) Merge(other EnvMap)

Merge merges the other env map into this env map.

func (EnvMap) NewExpander

func (em EnvMap) NewExpander() func(string) string

Expand performs shell expansion using this EnvMap.

type EnvVarRef added in v1.1.0

type EnvVarRef struct {
	Name         string
	DefaultValue string
	Index        [2]int
}

func CaptureEnvNameAndDefaultValue added in v1.1.0

func CaptureEnvNameAndDefaultValue(s string) (refs []EnvVarRef, ok bool)

Jump to

Keyboard shortcuts

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