主要变更: - 新增B端认证系统(后台+H5):登录、登出、Token刷新、密码修改 - 完善商户管理和商户账号管理功能 - 补全单元测试(ShopService: 72.5%, ShopAccountService: 79.8%) - 新增集成测试(商户管理+商户账号管理) - 归档OpenSpec提案(add-shop-account-management, implement-b-end-auth-system) - 完善文档(使用指南、API文档、认证架构说明) 测试统计: - 13个测试套件,37个测试用例,100%通过率 - 平均覆盖率76.2%,达标 OpenSpec验证:通过(strict模式)
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package routes
|
||
|
||
import (
|
||
"regexp"
|
||
|
||
"github.com/gofiber/fiber/v2"
|
||
|
||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||
)
|
||
|
||
// RouteSpec 定义接口文档元数据
|
||
type RouteSpec struct {
|
||
Summary string
|
||
Input interface{} // 请求参数结构体 (Query/Path/Body)
|
||
Output interface{} // 响应参数结构体
|
||
Tags []string
|
||
Auth bool // 是否需要认证图标 (预留)
|
||
}
|
||
|
||
// pathParamRegex 用于匹配 Fiber 的路径参数格式 /:param
|
||
var pathParamRegex = regexp.MustCompile(`/:([a-zA-Z0-9_]+)`)
|
||
|
||
// Register 封装后的注册函数
|
||
// router: Fiber 路由组
|
||
// doc: 文档生成器 (如果在运行 Web 服务时为 nil,在生成文档时为非 nil)
|
||
// basePath: 当前路由组的基础路径 (用于文档生成)
|
||
// method, path: HTTP 方法和路径
|
||
// handler: Fiber Handler
|
||
// spec: 文档元数据
|
||
func Register(router fiber.Router, doc *openapi.Generator, basePath, method, path string, handler fiber.Handler, spec RouteSpec) {
|
||
router.Add(method, path, handler)
|
||
|
||
if doc != nil {
|
||
fullPath := basePath + path
|
||
openapiPath := pathParamRegex.ReplaceAllString(fullPath, "/{$1}")
|
||
doc.AddOperation(method, openapiPath, spec.Summary, spec.Input, spec.Output, spec.Auth, spec.Tags...)
|
||
}
|
||
}
|