本文整理汇总了Golang中github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.Environment.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Environment.Get方法的具体用法?Golang Environment.Get怎么用?Golang Environment.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/rkt/Godeps/_workspace/src/github.com/appc/spec/schema/types.Environment
的用法示例。
在下文中一共展示了Environment.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeEnvFile
// writeEnvFile creates an environment file for given app name, the minimum
// required environment variables by the appc spec will be set to sensible
// defaults here if they're not provided by env.
func writeEnvFile(p *stage1commontypes.Pod, env types.Environment, appName types.ACName, privateUsers string) error {
ef := bytes.Buffer{}
for dk, dv := range defaultEnv {
if _, exists := env.Get(dk); !exists {
fmt.Fprintf(&ef, "%s=%s\000", dk, dv)
}
}
for _, e := range env {
fmt.Fprintf(&ef, "%s=%s\000", e.Name, e.Value)
}
uidRange := uid.NewBlankUidRange()
if err := uidRange.Deserialize([]byte(privateUsers)); err != nil {
return err
}
envFilePath := EnvFilePath(p.Root, appName)
if err := ioutil.WriteFile(envFilePath, ef.Bytes(), 0644); err != nil {
return err
}
if uidRange.Shift != 0 && uidRange.Count != 0 {
if err := os.Chown(envFilePath, int(uidRange.Shift), int(uidRange.Shift)); err != nil {
return err
}
}
return nil
}
示例2: writeEnvFile
// writeEnvFile creates an environment file for given app id
// the minimum required environment variables by the appc spec will be set to sensible
// defaults here if they're not provided by env.
func (p *Pod) writeEnvFile(env types.Environment, id types.Hash) error {
ef := bytes.Buffer{}
for dk, dv := range defaultEnv {
if _, exists := env.Get(dk); !exists {
fmt.Fprintf(&ef, "%s=%s\000", dk, dv)
}
}
for _, e := range env {
fmt.Fprintf(&ef, "%s=%s\000", e.Name, e.Value)
}
return ioutil.WriteFile(EnvFilePath(p.Root, id), ef.Bytes(), 0640)
}
示例3: MergeEnvs
// MergeEnvs amends appEnv setting variables in setEnv before setting anything new from os.Environ if inheritEnv = true
// setEnv is expected to be in the os.Environ() key=value format
func MergeEnvs(appEnv *types.Environment, inheritEnv bool, setEnv []string) {
for _, ev := range setEnv {
pair := strings.SplitN(ev, "=", 2)
appEnv.Set(pair[0], pair[1])
}
if inheritEnv {
for _, ev := range os.Environ() {
pair := strings.SplitN(ev, "=", 2)
if _, exists := appEnv.Get(pair[0]); !exists {
appEnv.Set(pair[0], pair[1])
}
}
}
}