2017-04-07 01:13:36 +00:00
|
|
|
package host
|
|
|
|
|
2017-04-07 09:26:46 +00:00
|
|
|
import (
|
|
|
|
"gopkg.in/macaron.v1"
|
|
|
|
"github.com/ouqiang/gocron/models"
|
|
|
|
"github.com/ouqiang/gocron/modules/utils"
|
|
|
|
"github.com/ouqiang/gocron/modules/logger"
|
|
|
|
)
|
2017-04-07 01:13:36 +00:00
|
|
|
|
2017-04-08 09:15:30 +00:00
|
|
|
func Index(ctx *macaron.Context) {
|
|
|
|
hostModel := new(models.Host)
|
|
|
|
hosts, err := hostModel.List()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(err)
|
|
|
|
}
|
|
|
|
ctx.Data["Title"] = "主机列表"
|
2017-04-09 09:55:55 +00:00
|
|
|
ctx.Data["URI"] = "/host"
|
2017-04-10 09:37:16 +00:00
|
|
|
ctx.Data["Hosts"] = hosts
|
2017-04-08 09:15:30 +00:00
|
|
|
ctx.HTML(200, "host/index")
|
|
|
|
}
|
|
|
|
|
2017-04-07 01:13:36 +00:00
|
|
|
func Create(ctx *macaron.Context) {
|
2017-04-08 09:15:30 +00:00
|
|
|
ctx.Data["Title"] = "添加主机"
|
2017-04-09 09:55:55 +00:00
|
|
|
ctx.Data["URI"] = "/host/create"
|
2017-04-07 01:13:36 +00:00
|
|
|
ctx.HTML(200, "host/create")
|
|
|
|
}
|
|
|
|
|
2017-04-07 09:26:46 +00:00
|
|
|
type HostForm struct {
|
|
|
|
Name string `binding:"Required"`
|
|
|
|
Alias string `binding:"Required"`
|
|
|
|
Username string `binding:"Required"`
|
|
|
|
Password string
|
|
|
|
Port int `binding:"Required;Range(1-65535)"`
|
|
|
|
Remark string `binding:"Required"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func Store(ctx *macaron.Context, form HostForm) string {
|
|
|
|
json := utils.Json{}
|
|
|
|
hostModel := new(models.Host)
|
|
|
|
hostModel.Name = form.Name
|
|
|
|
hostModel.Alias = form.Alias
|
|
|
|
hostModel.Username = form.Username
|
|
|
|
hostModel.Password = form.Password
|
|
|
|
hostModel.Port = form.Port
|
|
|
|
hostModel.Remark = form.Remark
|
|
|
|
_, err := hostModel.Create()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(err)
|
|
|
|
return json.Failure(utils.ResponseFailure, "保存失败")
|
|
|
|
}
|
2017-04-07 01:13:36 +00:00
|
|
|
|
2017-04-07 09:26:46 +00:00
|
|
|
return json.Success("保存成功", nil)
|
2017-04-07 01:13:36 +00:00
|
|
|
}
|