swirl/controller/container.go

63 lines
1.6 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/auxo/util/cast"
"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
"github.com/cuigh/swirl/model"
)
type ContainerController struct {
List web.HandlerFunc `path:"/" name:"container.list" authorize:"!" desc:"container list page"`
Detail web.HandlerFunc `path:"/:id/detail" name:"container.detail" authorize:"!" desc:"container detail page"`
Raw web.HandlerFunc `path:"/:id/raw" name:"container.raw" authorize:"!" desc:"container raw page"`
}
func Container() (c *ContainerController) {
c = &ContainerController{}
c.List = func(ctx web.Context) error {
name := ctx.Q("name")
page := cast.ToIntD(ctx.Q("page"), 1)
containers, totalCount, err := docker.ContainerList(name, page, model.PageSize)
if err != nil {
return err
}
m := newPagerModel(ctx, totalCount, model.PageSize, page).
Add("Name", name).
Add("Containers", containers)
return ctx.Render("container/list", m)
}
c.Detail = func(ctx web.Context) error {
id := ctx.P("id")
container, err := docker.ContainerInspect(id)
if err != nil {
return err
}
m := newModel(ctx).Add("Container", container)
return ctx.Render("container/detail", m)
}
c.Raw = func(ctx web.Context) error {
id := ctx.P("id")
container, raw, err := docker.ContainerInspectRaw(id)
if err != nil {
return err
}
2017-10-10 07:26:07 +00:00
j, err := misc.JSONIndent(raw)
2017-09-26 12:50:09 +00:00
if err != nil {
return err
}
2017-10-10 07:26:07 +00:00
m := newModel(ctx).Add("Container", container).Add("Raw", j)
2017-09-26 12:50:09 +00:00
return ctx.Render("container/raw", m)
}
return
}