本文整理匯總了Golang中v/io/x/lib/envvar.Vars.ToMap方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vars.ToMap方法的具體用法?Golang Vars.ToMap怎麽用?Golang Vars.ToMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類v/io/x/lib/envvar.Vars
的用法示例。
在下文中一共展示了Vars.ToMap方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExpandEnv
// ExpandEnv expands all instances of the JIRI_ROOT variable in the supplied
// environment with the root from jirix.
func ExpandEnv(x *X, env *envvar.Vars) {
e := env.ToMap()
rootEnv := "${" + RootEnv + "}"
for k, v := range e {
n := strings.Replace(v, rootEnv, x.Root, -1)
if n != v {
env.Set(k, n)
}
}
}
示例2: MergeEnv
// MergeEnv merges environment variables in base with those
// in vars according to the suppled policies.
func MergeEnv(policies map[string]MergePolicy, base *envvar.Vars, vars ...[]string) {
// Remove any variables that have the IgnoreBase policy.
for k, _ := range base.ToMap() {
switch policies[k].Action {
case Ignore, IgnoreBaseAndAppend, IgnoreBaseAndPrepend, IgnoreBaseAndUseFirst, IgnoreBaseAndUseLast:
base.Delete(k)
}
}
for _, ev := range vars {
for _, tmp := range ev {
k, v := envvar.SplitKeyValue(tmp)
policy := policies[k]
action := policy.Action
switch policy.Action {
case IgnoreBaseAndAppend:
action = Append
case IgnoreBaseAndPrepend:
action = Prepend
case IgnoreBaseAndUseLast:
action = Last
case IgnoreBaseAndUseFirst:
action = First
}
switch action {
case Ignore, IgnoreProfiles:
continue
case Append, Prepend:
sep := policy.Separator
ov := base.GetTokens(k, sep)
nv := envvar.SplitTokens(v, sep)
if action == Append {
base.SetTokens(k, append(ov, nv...), sep)
} else {
base.SetTokens(k, append(nv, ov...), sep)
}
case First:
if !base.Contains(k) {
base.Set(k, v)
}
case Last:
base.Set(k, v)
}
}
}
}