feat: 添加数据库集成、定时任务调度器和事件Hook体系
- 新增数据库配置项(DB_TYPE, DB_HOST, DB_PORT等),支持MySQL和PostgreSQL - 集成GORM实现数据库连接和自动迁移功能 - 添加定时任务调度器(cmd/scheduler),基于robfig/cron实现秒级调度 - 实现事件Hook体系,支持同步/异步处理和优先级排序 - 更新构建脚本,编译server、cli、scheduler三个二进制文件 - 配置systemd服务管理定时任务调度器 - 重构项目结构,新增crontab和hooks目录模块 - 更新README文档,完善各组件使用说明和部署配置
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package hooks
|
||||
|
||||
import "context"
|
||||
|
||||
// EventType 业务事件类型,按项目需求在此扩展
|
||||
type EventType string
|
||||
|
||||
// Handler 事件处理器接口
|
||||
type Handler interface {
|
||||
Handle(ctx context.Context, event EventType, payload *EventPayload) error
|
||||
}
|
||||
|
||||
// HandlerFunc 函数适配器,方便用匿名函数注册 handler
|
||||
type HandlerFunc func(ctx context.Context, event EventType, payload *EventPayload) error
|
||||
|
||||
func (f HandlerFunc) Handle(ctx context.Context, event EventType, payload *EventPayload) error {
|
||||
return f(ctx, event, payload)
|
||||
}
|
||||
|
||||
// EventPayload 事件携带的上下文信息
|
||||
type EventPayload struct {
|
||||
UserID int
|
||||
Extra map[string]any
|
||||
}
|
||||
Reference in New Issue
Block a user