gocron/routers/host/host.go

42 lines
1.1 KiB
Go
Raw Normal View History

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
func Create(ctx *macaron.Context) {
ctx.Data["Title"] = "主机管理"
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)"`
LoginType int8 `binding:"Required"`
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.LoginType = models.LoginType(form.LoginType);
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
}