forked from xinliangnote/go-gin-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron.go
64 lines (53 loc) · 1.24 KB
/
cron.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cron
import (
"net/http"
"github.com/imlida/go-gin-api/internal/code"
"github.com/imlida/go-gin-api/internal/pkg/core"
"github.com/imlida/go-gin-api/internal/repository/mysql"
"github.com/imlida/go-gin-api/internal/repository/redis"
"go.uber.org/zap"
)
type handler struct {
logger *zap.Logger
cache redis.Repo
db mysql.Repo
}
func New(logger *zap.Logger, db mysql.Repo, cache redis.Repo) *handler {
return &handler{
logger: logger,
cache: cache,
db: db,
}
}
func (h *handler) Add() core.HandlerFunc {
return func(ctx core.Context) {
ctx.HTML("cron_task_add", nil)
}
}
func (h *handler) Edit() core.HandlerFunc {
type editRequest struct {
Id string `uri:"id"` // 主键ID
}
type editResponse struct {
HashID string `json:"hash_id"` // hashID
}
return func(ctx core.Context) {
req := new(editRequest)
if err := ctx.ShouldBindURI(req); err != nil {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ParamBindError,
code.Text(code.ParamBindError)).WithError(err),
)
return
}
obj := new(editResponse)
obj.HashID = req.Id
ctx.HTML("cron_task_edit", obj)
}
}
func (h *handler) List() core.HandlerFunc {
return func(ctx core.Context) {
ctx.HTML("cron_task_list", nil)
}
}