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

70 lines
4.7 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"
)
// CertRoutes 证书、DNS、账户路由
func CertRoutes(i do.Injector) (Endpoints, error) {
cert := do.MustInvoke[*service.CertService](i)
certDNS := do.MustInvoke[*service.CertDNSService](i)
certAccount := do.MustInvoke[*service.CertAccountService](i)
return Endpoints{
// 顶层选项
{Method: http.MethodGet, Path: "/api/cert/ca_providers", Handler: cert.CAProviders, Summary: "CA 提供商列表", Tags: []string{"证书"}},
{Method: http.MethodGet, Path: "/api/cert/dns_providers", Handler: cert.DNSProviders, Summary: "DNS 提供商列表", Tags: []string{"证书"}},
{Method: http.MethodGet, Path: "/api/cert/algorithms", Handler: cert.Algorithms, Summary: "密钥算法列表", Tags: []string{"证书"}},
// 证书
{Method: http.MethodGet, Path: "/api/cert/cert", Handler: cert.List, Summary: "证书列表", Tags: []string{"证书"},
Request: request.Paginate{}, Response: service.Envelope[service.Page[*types.CertList]]{}},
{Method: http.MethodPost, Path: "/api/cert/cert", Handler: cert.Create, Summary: "创建证书", Tags: []string{"证书"},
Request: request.CertCreate{}, Response: service.Envelope[biz.Cert]{}},
{Method: http.MethodPost, Path: "/api/cert/cert/upload", Handler: cert.Upload, Summary: "上传证书", Tags: []string{"证书"},
Request: request.CertUpload{}, Response: service.Envelope[biz.Cert]{}},
{Method: http.MethodPut, Path: "/api/cert/cert/{id}", Handler: cert.Update, Summary: "更新证书", Tags: []string{"证书"},
Request: request.CertUpdate{}},
{Method: http.MethodGet, Path: "/api/cert/cert/{id}", Handler: cert.Get, Summary: "获取证书", Tags: []string{"证书"},
Request: request.ID{}, Response: service.Envelope[biz.Cert]{}},
{Method: http.MethodDelete, Path: "/api/cert/cert/{id}", Handler: cert.Delete, Summary: "删除证书", Tags: []string{"证书"},
Request: request.ID{}},
{Method: http.MethodPost, Path: "/api/cert/cert/{id}/obtain_auto", Handler: cert.ObtainAuto, Summary: "自动签发证书", Tags: []string{"证书"},
Request: request.ID{}},
{Method: http.MethodPost, Path: "/api/cert/cert/{id}/obtain_self_signed", Handler: cert.ObtainSelfSigned, Summary: "签发自签名证书", Tags: []string{"证书"},
Request: request.ID{}},
{Method: http.MethodPost, Path: "/api/cert/cert/{id}/renew", Handler: cert.Renew, Summary: "续签证书", Tags: []string{"证书"},
Request: request.ID{}},
{Method: http.MethodPost, Path: "/api/cert/cert/{id}/deploy", Handler: cert.Deploy, Summary: "部署证书", Tags: []string{"证书"},
Request: request.CertDeploy{}},
// DNS
{Method: http.MethodGet, Path: "/api/cert/dns", Handler: certDNS.List, Summary: "DNS 列表", Tags: []string{"证书"},
Request: request.Paginate{}, Response: service.Envelope[service.Page[*biz.CertDNS]]{}},
{Method: http.MethodPost, Path: "/api/cert/dns", Handler: certDNS.Create, Summary: "创建 DNS", Tags: []string{"证书"},
Request: request.CertDNSCreate{}, Response: service.Envelope[biz.CertDNS]{}},
{Method: http.MethodPut, Path: "/api/cert/dns/{id}", Handler: certDNS.Update, Summary: "更新 DNS", Tags: []string{"证书"},
Request: request.CertDNSUpdate{}},
{Method: http.MethodGet, Path: "/api/cert/dns/{id}", Handler: certDNS.Get, Summary: "获取 DNS", Tags: []string{"证书"},
Request: request.ID{}, Response: service.Envelope[biz.CertDNS]{}},
{Method: http.MethodDelete, Path: "/api/cert/dns/{id}", Handler: certDNS.Delete, Summary: "删除 DNS", Tags: []string{"证书"},
Request: request.ID{}},
// 账户
{Method: http.MethodGet, Path: "/api/cert/account", Handler: certAccount.List, Summary: "账户列表", Tags: []string{"证书"},
Request: request.Paginate{}, Response: service.Envelope[service.Page[*biz.CertAccount]]{}},
{Method: http.MethodPost, Path: "/api/cert/account", Handler: certAccount.Create, Summary: "创建账户", Tags: []string{"证书"},
Request: request.CertAccountCreate{}, Response: service.Envelope[biz.CertAccount]{}},
{Method: http.MethodPut, Path: "/api/cert/account/{id}", Handler: certAccount.Update, Summary: "更新账户", Tags: []string{"证书"},
Request: request.CertAccountUpdate{}},
{Method: http.MethodGet, Path: "/api/cert/account/{id}", Handler: certAccount.Get, Summary: "获取账户", Tags: []string{"证书"},
Request: request.ID{}, Response: service.Envelope[biz.CertAccount]{}},
{Method: http.MethodDelete, Path: "/api/cert/account/{id}", Handler: certAccount.Delete, Summary: "删除账户", Tags: []string{"证书"},
Request: request.ID{}},
}, nil
}