Files
panel/internal/biz/webhook.go
T
耗子andClaude Opus 4.8 443516a2cf refactor!: 迁移至 samber/do 依赖注入与三层架构
依赖注入:
- 移除 google/wire(含 wire.go/wire_gen.go 与全部 ProviderSet),
  改用 samber/do v2 单注入器 + 双入口惰性构建
- 贡献模型替代命令式注册:路由 routes:、命令 commands:、
  任务 jobs: 前缀经 internal/registry 收集与校验
- 构造函数统一 func NewXxx(i do.Injector) (T, error)

三层架构:
- 补全用例层:每个 biz.XxxRepo 配 XxxUsecase,
  service/command/job 表现层只依赖用例,不再直接引用仓储

路由与文档:
- route/http.go 按域拆为声明式 Endpoint 贡献,
  Endpoint 承载登录白名单与端点限流语义
- 调试模式下提供 OpenAPI 3.1 文档:/openapi.json 与 /docs(Scalar),
  从 validate 标签生成

目录与依赖:
- internal/http/{middleware,request,rule} 拍平至 internal/*
- CLI 命令拆至 internal/command
- 日志轮转 timberjack 换为 libtnb/logrotate
- 升级 validator/cron/sessions/gormstore/sqlite/securecookie
- 数据库迁移保持 gormigrate 不变

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 21:54:22 +08:00

69 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package biz
import (
"context"
"time"
"github.com/acepanel/panel/v3/internal/request"
)
type WebHook struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"not null;default:''" json:"name"` // 钩子名称
Key string `gorm:"not null;uniqueIndex" json:"key"` // 唯一标识(用于 URL)
Script string `gorm:"not null;default:''" json:"script"` // 脚本内容
Raw bool `gorm:"not null;default:false" json:"raw"` // 是否以原始格式返回输出
User string `gorm:"not null;default:''" json:"user"` // 以哪个用户身份执行脚本
Status bool `gorm:"not null;default:true" json:"status"` // 启用状态
CallCount uint `gorm:"not null;default:0" json:"call_count"` // 调用次数
LastCallAt time.Time `json:"last_call_at"` // 上次调用时间
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type WebHookRepo interface {
List(page, limit uint) ([]*WebHook, int64, error)
Get(id uint) (*WebHook, error)
GetByKey(key string) (*WebHook, error)
Create(ctx context.Context, req *request.WebHookCreate) (*WebHook, error)
Update(ctx context.Context, req *request.WebHookUpdate) error
Delete(ctx context.Context, id uint) error
Call(key string) (string, error)
}
type WebHookUsecase struct {
repo WebHookRepo
}
func NewWebHookUsecase(repo WebHookRepo) *WebHookUsecase {
return &WebHookUsecase{repo: repo}
}
func (uc *WebHookUsecase) List(page, limit uint) ([]*WebHook, int64, error) {
return uc.repo.List(page, limit)
}
func (uc *WebHookUsecase) Get(id uint) (*WebHook, error) {
return uc.repo.Get(id)
}
func (uc *WebHookUsecase) GetByKey(key string) (*WebHook, error) {
return uc.repo.GetByKey(key)
}
func (uc *WebHookUsecase) Create(ctx context.Context, req *request.WebHookCreate) (*WebHook, error) {
return uc.repo.Create(ctx, req)
}
func (uc *WebHookUsecase) Update(ctx context.Context, req *request.WebHookUpdate) error {
return uc.repo.Update(ctx, req)
}
func (uc *WebHookUsecase) Delete(ctx context.Context, id uint) error {
return uc.repo.Delete(ctx, id)
}
func (uc *WebHookUsecase) Call(key string) (string, error) {
return uc.repo.Call(key)
}