mirror of
https://github.com/tnb-labs/panel.git
synced 2026-09-21 13:20:10 +08:00
依赖注入:
- 移除 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>
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/acepanel/panel/v3/internal/request"
|
|
)
|
|
|
|
type DatabaseType string
|
|
|
|
const (
|
|
DatabaseTypeMysql DatabaseType = "mysql"
|
|
DatabaseTypePostgresql DatabaseType = "postgresql"
|
|
DatabaseTypeMongoDB DatabaseType = "mongodb"
|
|
DatabaseTypeClickHouse DatabaseType = "clickhouse"
|
|
DatabaseTypeSQLite DatabaseType = "sqlite"
|
|
DatabaseTypeRedis DatabaseType = "redis"
|
|
DatabaseTypeElasticsearch DatabaseType = "elasticsearch"
|
|
)
|
|
|
|
type Database struct {
|
|
Type DatabaseType `json:"type"`
|
|
Name string `json:"name"`
|
|
Server string `json:"server"`
|
|
ServerID uint `json:"server_id"`
|
|
Encoding string `json:"encoding"`
|
|
Comment string `json:"comment"`
|
|
}
|
|
|
|
type DatabaseRepo interface {
|
|
List(page, limit uint, typ string) ([]*Database, int64, error)
|
|
Create(ctx context.Context, req *request.DatabaseCreate) error
|
|
Delete(ctx context.Context, serverID uint, name string) error
|
|
Comment(req *request.DatabaseComment) error
|
|
}
|
|
|
|
// DatabaseUsecase 数据库业务用例
|
|
type DatabaseUsecase struct {
|
|
repo DatabaseRepo
|
|
}
|
|
|
|
func NewDatabaseUsecase(repo DatabaseRepo) *DatabaseUsecase {
|
|
return &DatabaseUsecase{repo: repo}
|
|
}
|
|
|
|
func (uc *DatabaseUsecase) List(page, limit uint, typ string) ([]*Database, int64, error) {
|
|
return uc.repo.List(page, limit, typ)
|
|
}
|
|
|
|
func (uc *DatabaseUsecase) Create(ctx context.Context, req *request.DatabaseCreate) error {
|
|
return uc.repo.Create(ctx, req)
|
|
}
|
|
|
|
func (uc *DatabaseUsecase) Delete(ctx context.Context, serverID uint, name string) error {
|
|
return uc.repo.Delete(ctx, serverID, name)
|
|
}
|
|
|
|
func (uc *DatabaseUsecase) Comment(req *request.DatabaseComment) error {
|
|
return uc.repo.Comment(req)
|
|
}
|