Files
panel/internal/route/website.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

51 lines
2.9 KiB
Go

package route
import (
"net/http"
"github.com/samber/do/v2"
"github.com/acepanel/panel/v3/internal/biz"
"github.com/acepanel/panel/v3/internal/request"
"github.com/acepanel/panel/v3/internal/service"
"github.com/acepanel/panel/v3/pkg/types"
)
// WebsiteRoutes 网站相关路由
func WebsiteRoutes(i do.Injector) (Endpoints, error) {
svc := do.MustInvoke[*service.WebsiteService](i)
return Endpoints{
{Method: http.MethodGet, Path: "/api/website/rewrites", Handler: svc.GetRewrites,
Summary: "获取伪静态规则", Tags: []string{"网站"}},
{Method: http.MethodGet, Path: "/api/website/default_config", Handler: svc.GetDefaultConfig,
Summary: "获取默认配置", Tags: []string{"网站"}},
{Method: http.MethodPost, Path: "/api/website/default_config", Handler: svc.UpdateDefaultConfig,
Summary: "保存默认配置", Tags: []string{"网站"}, Request: request.WebsiteDefaultConfig{}},
{Method: http.MethodPost, Path: "/api/website/cert", Handler: svc.UpdateCert,
Summary: "更新证书", Tags: []string{"网站"}, Request: request.WebsiteUpdateCert{}},
{Method: http.MethodGet, Path: "/api/website", Handler: svc.List,
Summary: "网站列表", Tags: []string{"网站"},
Request: request.WebsiteList{}, Response: service.Envelope[service.Page[*biz.Website]]{}},
{Method: http.MethodPost, Path: "/api/website", Handler: svc.Create,
Summary: "创建网站", Tags: []string{"网站"}, Request: request.WebsiteCreate{}},
{Method: http.MethodGet, Path: "/api/website/{id}", Handler: svc.Get,
Summary: "获取网站配置", Tags: []string{"网站"},
Request: request.ID{}, Response: service.Envelope[types.WebsiteSetting]{}},
{Method: http.MethodPut, Path: "/api/website/{id}", Handler: svc.Update,
Summary: "保存网站配置", Tags: []string{"网站"}, Request: request.WebsiteUpdate{}},
{Method: http.MethodDelete, Path: "/api/website/{id}", Handler: svc.Delete,
Summary: "删除网站", Tags: []string{"网站"}, Request: request.WebsiteDelete{}},
{Method: http.MethodPost, Path: "/api/website/{id}/update_remark", Handler: svc.UpdateRemark,
Summary: "更新备注", Tags: []string{"网站"}, Request: request.WebsiteUpdateRemark{}},
{Method: http.MethodPost, Path: "/api/website/{id}/reset_config", Handler: svc.ResetConfig,
Summary: "重置配置", Tags: []string{"网站"}, Request: request.ID{}},
{Method: http.MethodPost, Path: "/api/website/{id}/status", Handler: svc.UpdateStatus,
Summary: "修改状态", Tags: []string{"网站"}, Request: request.WebsiteUpdateStatus{}},
{Method: http.MethodPost, Path: "/api/website/{id}/expire_at", Handler: svc.UpdateExpireAt,
Summary: "修改到期时间", Tags: []string{"网站"}, Request: request.WebsiteUpdateExpireAt{}},
{Method: http.MethodPost, Path: "/api/website/{id}/obtain_cert", Handler: svc.ObtainCert,
Summary: "签发证书", Tags: []string{"网站"}, Request: request.WebsiteObtainCert{}},
}, nil
}