Files
go-gin-api/internal/api/cron/handler.go
T
新亮 4c37a7e6b5 feature(1.2.8): swagger 接口文档新增 Security
- 将 middleware 命名为 interceptor
- 将 deploy 命名为 deployments
- 移除 pkg/errno
- 使用 proposal 目录
- 优化代码
2021-11-28 13:25:27 +08:00

68 lines
1.6 KiB
Go

package cron
import (
"github.com/xinliangnote/go-gin-api/configs"
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
cronRepo "github.com/xinliangnote/go-gin-api/internal/repository/cron"
"github.com/xinliangnote/go-gin-api/internal/repository/mysql"
"github.com/xinliangnote/go-gin-api/internal/repository/redis"
"github.com/xinliangnote/go-gin-api/internal/services/cron"
"github.com/xinliangnote/go-gin-api/pkg/hash"
"go.uber.org/zap"
)
var _ Handler = (*handler)(nil)
type Handler interface {
i()
// Create 创建任务
// @Tags API.cron
// @Router /api/cron [post]
Create() core.HandlerFunc
// Modify 编辑任务
// @Tags API.cron
// @Router /api/cron/{id} [post]
Modify() core.HandlerFunc
// List 任务列表
// @Tags API.cron
// @Router /api/cron [get]
List() core.HandlerFunc
// UpdateUsed 更新任务为启用/禁用
// @Tags API.cron
// @Router /api/cron/used [patch]
UpdateUsed() core.HandlerFunc
// Detail 获取单条任务详情
// @Tags API.cron
// @Router /api/cron/{id} [get]
Detail() core.HandlerFunc
// Execute 手动执行任务
// @Tags API.cron
// @Router /api/cron/{id} [patch]
Execute() core.HandlerFunc
}
type handler struct {
logger *zap.Logger
cache redis.Repo
hashids hash.Hash
cronService cron.Service
}
func New(logger *zap.Logger, db mysql.Repo, cache redis.Repo, cronServer cronRepo.Server) Handler {
return &handler{
logger: logger,
cache: cache,
hashids: hash.New(configs.Get().HashIds.Secret, configs.Get().HashIds.Length),
cronService: cron.New(db, cache, cronServer),
}
}
func (h *handler) i() {}