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>
101 lines
2.5 KiB
Go
101 lines
2.5 KiB
Go
package biz
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/acepanel/panel/v3/pkg/api"
|
|
"github.com/acepanel/panel/v3/pkg/types"
|
|
)
|
|
|
|
type App struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
Slug string `gorm:"not null;default:'';unique" json:"slug"`
|
|
Channel string `gorm:"not null;default:''" json:"channel"`
|
|
Version string `gorm:"not null;default:''" json:"version"`
|
|
Show bool `gorm:"not null;default:false" json:"show"`
|
|
ShowOrder int `gorm:"not null;default:0" json:"show_order"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type AppRepo interface {
|
|
Categories() []types.LV
|
|
All() api.Apps
|
|
Get(slug string) (*api.App, error)
|
|
UpdateExist(slug string) bool
|
|
Installed() ([]*App, error)
|
|
GetInstalled(slug string) (*App, error)
|
|
GetInstalledAll(query string, cond ...string) ([]*App, error)
|
|
GetHomeShow() ([]map[string]string, error)
|
|
IsInstalled(query string, cond ...any) (bool, error)
|
|
Install(channel, slug string) error
|
|
UnInstall(slug string) error
|
|
Update(slug string) error
|
|
UpdateShow(slug string, show bool) error
|
|
UpdateOrder(slugs []string) error
|
|
}
|
|
|
|
type AppUsecase struct {
|
|
repo AppRepo
|
|
}
|
|
|
|
func NewAppUsecase(repo AppRepo) *AppUsecase {
|
|
return &AppUsecase{repo: repo}
|
|
}
|
|
|
|
func (uc *AppUsecase) Categories() []types.LV {
|
|
return uc.repo.Categories()
|
|
}
|
|
|
|
func (uc *AppUsecase) All() api.Apps {
|
|
return uc.repo.All()
|
|
}
|
|
|
|
func (uc *AppUsecase) Get(slug string) (*api.App, error) {
|
|
return uc.repo.Get(slug)
|
|
}
|
|
|
|
func (uc *AppUsecase) UpdateExist(slug string) bool {
|
|
return uc.repo.UpdateExist(slug)
|
|
}
|
|
|
|
func (uc *AppUsecase) Installed() ([]*App, error) {
|
|
return uc.repo.Installed()
|
|
}
|
|
|
|
func (uc *AppUsecase) GetInstalled(slug string) (*App, error) {
|
|
return uc.repo.GetInstalled(slug)
|
|
}
|
|
|
|
func (uc *AppUsecase) GetInstalledAll(query string, cond ...string) ([]*App, error) {
|
|
return uc.repo.GetInstalledAll(query, cond...)
|
|
}
|
|
|
|
func (uc *AppUsecase) GetHomeShow() ([]map[string]string, error) {
|
|
return uc.repo.GetHomeShow()
|
|
}
|
|
|
|
func (uc *AppUsecase) IsInstalled(query string, cond ...any) (bool, error) {
|
|
return uc.repo.IsInstalled(query, cond...)
|
|
}
|
|
|
|
func (uc *AppUsecase) Install(channel, slug string) error {
|
|
return uc.repo.Install(channel, slug)
|
|
}
|
|
|
|
func (uc *AppUsecase) UnInstall(slug string) error {
|
|
return uc.repo.UnInstall(slug)
|
|
}
|
|
|
|
func (uc *AppUsecase) Update(slug string) error {
|
|
return uc.repo.Update(slug)
|
|
}
|
|
|
|
func (uc *AppUsecase) UpdateShow(slug string, show bool) error {
|
|
return uc.repo.UpdateShow(slug, show)
|
|
}
|
|
|
|
func (uc *AppUsecase) UpdateOrder(slugs []string) error {
|
|
return uc.repo.UpdateOrder(slugs)
|
|
}
|