swirl/controller/task.go

49 lines
1.0 KiB
Go
Raw Normal View History

2017-09-26 12:50:09 +00:00
package controller
import (
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz/docker"
2017-10-10 07:26:07 +00:00
"github.com/cuigh/swirl/misc"
2017-09-26 12:50:09 +00:00
)
2017-10-11 03:26:03 +00:00
// TaskController is a controller of swarm task
2017-09-26 12:50:09 +00:00
type TaskController struct {
Detail web.HandlerFunc `path:"/:id/detail" name:"task.detail" authorize:"!" desc:"task detail page"`
Raw web.HandlerFunc `path:"/:id/raw" name:"task.raw" authorize:"!" desc:"task raw page"`
}
2017-10-11 03:26:03 +00:00
// Task creates an instance of TaskController
2017-09-26 12:50:09 +00:00
func Task() (c *TaskController) {
2017-10-11 03:26:03 +00:00
return &TaskController{
Detail: taskDetail,
Raw: taskRaw,
}
}
2017-09-26 12:50:09 +00:00
2017-10-11 03:26:03 +00:00
func taskDetail(ctx web.Context) error {
id := ctx.P("id")
task, _, err := docker.TaskInspect(id)
if err != nil {
return err
2017-09-26 12:50:09 +00:00
}
2017-10-11 03:26:03 +00:00
m := newModel(ctx).Add("Task", task)
return ctx.Render("task/detail", m)
}
2017-09-26 12:50:09 +00:00
2017-10-11 03:26:03 +00:00
func taskRaw(ctx web.Context) error {
id := ctx.P("id")
task, raw, err := docker.TaskInspect(id)
if err != nil {
return err
}
2017-09-26 12:50:09 +00:00
2017-10-11 03:26:03 +00:00
j, err := misc.JSONIndent(raw)
if err != nil {
return err
2017-09-26 12:50:09 +00:00
}
2017-10-11 03:26:03 +00:00
m := newModel(ctx).Add("Task", task).Add("Raw", j)
return ctx.Render("task/raw", m)
2017-09-26 12:50:09 +00:00
}