gocron/routers/routers.go

81 lines
1.9 KiB
Go
Raw Normal View History

2017-03-24 05:06:53 +00:00
package routers
2017-03-24 09:55:44 +00:00
import (
2017-04-02 02:38:49 +00:00
"github.com/go-macaron/binding"
2017-04-07 01:22:00 +00:00
"github.com/ouqiang/gocron/routers/install"
2017-04-02 02:38:49 +00:00
"gopkg.in/macaron.v1"
2017-04-07 01:22:00 +00:00
"github.com/ouqiang/gocron/routers/task"
"github.com/ouqiang/gocron/routers/host"
"github.com/ouqiang/gocron/routers/tasklog"
2017-04-09 09:55:55 +00:00
"runtime"
"strconv"
2017-03-24 09:55:44 +00:00
)
2017-03-24 05:06:53 +00:00
// 路由注册
func Register(m *macaron.Macaron) {
2017-04-02 02:38:49 +00:00
// 所有GET方法自动注册HEAD方法
m.SetAutoHead(true)
// 404错误
m.NotFound(func(ctx *macaron.Context) {
ctx.HTML(404, "error/404")
})
// 50x错误
m.InternalServerError(func(ctx *macaron.Context) {
ctx.HTML(500, "error/500")
})
// 首页
m.Get("/", func(ctx *macaron.Context) string {
return "go home"
})
// 系统安装
m.Group("/install", func() {
2017-04-07 01:13:36 +00:00
m.Get("", install.Create)
m.Post("/store", binding.Bind(install.InstallForm{}), install.Store)
})
// 用户
m.Group("/user", func() {
})
2017-04-09 09:55:55 +00:00
// 监控
m.Group("/monitor", func() {
m.Any("/goroutine-num", func(ctx *macaron.Context) string {
return "goroutine数量-" + strconv.Itoa(runtime.NumGoroutine())
})
})
2017-04-07 01:13:36 +00:00
// 任务
m.Group("/task", func() {
m.Get("/create", task.Create)
2017-04-07 09:26:46 +00:00
m.Post("/store", binding.Bind(task.TaskForm{}), task.Store)
m.Get("", task.Index)
m.Get("/log", tasklog.Index)
2017-04-07 01:13:36 +00:00
})
// 主机
m.Group("/host", func() {
m.Get("/create", host.Create)
2017-04-07 09:26:46 +00:00
m.Post("/store", binding.Bind(host.HostForm{}), host.Store)
m.Get("", host.Index)
2017-04-07 01:13:36 +00:00
})
// API接口
m.Group("/api/v1", func() {
2017-04-02 02:38:49 +00:00
})
2017-04-02 02:19:52 +00:00
}
func isAjaxRequest(ctx *macaron.Context) bool {
req := ctx.Req.Header.Get("X-Requested-With")
if req == "XMLHttpRequest" {
return true
}
return false
}
func isGetRequest(ctx *macaron.Context) bool {
return ctx.Req.Method == "GET"
}