本文整理匯總了Golang中github.com/tsuru/tsuru/provision.ScopedConfig.Envs方法的典型用法代碼示例。如果您正苦於以下問題:Golang ScopedConfig.Envs方法的具體用法?Golang ScopedConfig.Envs怎麽用?Golang ScopedConfig.Envs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/tsuru/tsuru/provision.ScopedConfig
的用法示例。
在下文中一共展示了ScopedConfig.Envs方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (c *dockerLogUpdate) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
if c.restart {
extra := ""
if c.pool != "" {
extra = fmt.Sprintf(" running on pool %s", c.pool)
}
msg := fmt.Sprintf("Are you sure you want to restart all apps%s?", extra)
if !c.Confirm(context, msg) {
return nil
}
}
url, err := cmd.GetURL("/docker/logs")
if err != nil {
return err
}
envList := []provision.Entry{
{Name: "log-driver", Value: c.logDriver},
}
for name, value := range c.logOpts {
envList = append(envList, provision.Entry{Name: name, Value: value})
}
conf := provision.ScopedConfig{}
if c.pool == "" {
conf.Envs = envList
} else {
conf.Pools = []provision.PoolEntry{{
Name: c.pool,
Envs: envList,
}}
}
b, err := json.Marshal(logsSetData{
Restart: c.restart,
Config: conf,
})
if err != nil {
return err
}
buffer := bytes.NewBuffer(b)
request, err := http.NewRequest("POST", url, buffer)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
return cmd.StreamJSONResponse(context.Stdout, response)
}
示例2: Run
func (c *EnvSetCmd) Run(context *cmd.Context, client *cmd.Client) error {
context.RawOutput()
url, err := cmd.GetURL("/docker/bs/env")
if err != nil {
return err
}
var envList []provision.Entry
for _, arg := range context.Args {
parts := strings.SplitN(arg, "=", 2)
if len(parts) < 2 {
return fmt.Errorf("invalid variable values")
}
if parts[0] == "" {
return fmt.Errorf("invalid variable values")
}
envList = append(envList, provision.Entry{Name: parts[0], Value: parts[1]})
}
conf := provision.ScopedConfig{}
if c.pool == "" {
conf.Envs = envList
} else {
conf.Pools = []provision.PoolEntry{{
Name: c.pool,
Envs: envList,
}}
}
b, err := json.Marshal(conf)
if err != nil {
return err
}
buffer := bytes.NewBuffer(b)
request, err := http.NewRequest("POST", url, buffer)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/json")
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
return cmd.StreamJSONResponse(context.Stdout, response)
}