本文整理汇总了Golang中github.com/codegangsta/cli.Context.exec方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.exec方法的具体用法?Golang Context.exec怎么用?Golang Context.exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.exec方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: run
func (rax *RaxCloud) run(ctx *cli.Context, eng *engine.Engine) (err error) {
if err = rax.configure(ctx); err == nil {
if _, name, err := rax.findTargetHost(); err == nil {
if name == "" {
rax.createHost(DASS_TARGET_PREFIX + RandomString()[:12])
}
} else {
return err
}
eng.Register("create", func(job *engine.Job) (status engine.Status) {
if ctx, err := rax.getHostContext(); err == nil {
defer ctx.Close()
return ctx.exec(job, func(client HttpClient) (status engine.Status) {
path := "/containers/create"
config := runconfig.ContainerConfigFromJob(job)
if data, err := json.Marshal(config); err != nil {
return job.Errorf("marshaling failure : %v", err)
} else if resp, err := client.Post(path, string(data)); err != nil {
return job.Error(err)
} else {
var container struct {
Id string
Warnings []string
}
if body, err := ioutil.ReadAll(resp.Body); err != nil {
return job.Errorf("Failed to copy response body: %v", err)
} else if err := json.Unmarshal([]byte(body), &container); err != nil {
return job.Errorf("Failed to read container info from body: %v", err)
} else {
job.Printf("%s\n", container.Id)
}
}
return engine.StatusOK
})
} else {
return job.Errorf("Failed to create host context: %v", err)
}
})
eng.Register("container_delete", func(job *engine.Job) (status engine.Status) {
if ctx, err := rax.getHostContext(); err == nil {
defer ctx.Close()
return ctx.exec(job, func(client HttpClient) (status engine.Status) {
path := fmt.Sprintf("/containers/%s?force=%s", job.Args[0], url.QueryEscape(job.Getenv("forceRemove")))
if _, err := client.Delete(path, ""); err != nil {
return job.Error(err)
}
return engine.StatusOK
})
} else {
return job.Errorf("Failed to create host context: %v", err)
}
})
eng.Register("containers", func(job *engine.Job) (status engine.Status) {
if ctx, err := rax.getHostContext(); err == nil {
defer ctx.Close()
return ctx.exec(job, func(client HttpClient) (status engine.Status) {
path := fmt.Sprintf("/containers/json?all=%s&limit=%s",
url.QueryEscape(job.Getenv("all")), url.QueryEscape(job.Getenv("limit")))
if resp, err := client.Get(path, ""); err != nil {
return job.Error(err)
} else {
created := engine.NewTable("Created", 0)
if body, err := ioutil.ReadAll(resp.Body); err != nil {
return job.Errorf("Failed to copy response body: %v", err)
} else if created.ReadListFrom(body); err != nil {
return job.Errorf("Failed to read list from body: %v", err)
} else {
created.WriteListTo(job.Stdout)
}
}
return engine.StatusOK
})
} else {
return job.Errorf("Failed to create host context: %v", err)
}
})
eng.Register("version", func(job *engine.Job) (status engine.Status) {
if ctx, err := rax.getHostContext(); err == nil {
defer ctx.Close()
return ctx.exec(job, func(client HttpClient) (status engine.Status) {
path := "/version"
if resp, err := client.Get(path, ""); err != nil {
return job.Errorf("Failed call %s(path:%s): %v", job.Name, path, err)
//.........这里部分代码省略.........