feat: 优化对接口元数据 Meta 的解析
This commit is contained in:
@@ -135,10 +135,6 @@ type server struct {
|
||||
}
|
||||
|
||||
// Start 启动服务
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:31 2025/2/7
|
||||
func (s *server) Start() {
|
||||
// 注册文档
|
||||
s.uiInstance.RegisterHandler(s.router, s.option.swaggerBaseUri)
|
||||
@@ -153,28 +149,16 @@ func (s *server) Start() {
|
||||
}
|
||||
|
||||
// Router 对外访问路由实例, 不建议直接用
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 17:35 2025/2/18
|
||||
func (s *server) Router() *gin.Engine {
|
||||
return s.router
|
||||
}
|
||||
|
||||
// Handler404 注册404的处理方法
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:01 2025/2/22
|
||||
func (s *server) Handler404(f gin.HandlerFunc) {
|
||||
s.router.NoRoute(f)
|
||||
}
|
||||
|
||||
// SetCustomRouter 自定义路由处理
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 16:09 2025/2/22
|
||||
func (s *server) SetCustomRouter(f func(r *gin.Engine)) {
|
||||
if nil == f {
|
||||
return
|
||||
@@ -183,10 +167,6 @@ func (s *server) SetCustomRouter(f func(r *gin.Engine)) {
|
||||
}
|
||||
|
||||
// Group 注册接口路由
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 19:35 2025/1/27
|
||||
func (s *server) Group(routerPrefix string, middlewareList []gin.HandlerFunc, cList ...any) {
|
||||
g := s.router.Group(routerPrefix)
|
||||
g.Use(middlewareList...)
|
||||
@@ -195,27 +175,29 @@ func (s *server) Group(routerPrefix string, middlewareList []gin.HandlerFunc, cL
|
||||
urlTable := cParser.Parse(c)
|
||||
for _, itemUriCfg := range urlTable {
|
||||
_ = s.uiInstance.DocInstance().AddApiFromInAndOut(routerPrefix, itemUriCfg.FormDataType, itemUriCfg.ResultDataType)
|
||||
method := strings.ToUpper(itemUriCfg.RequestMethod)
|
||||
handleFunc := s.RequestHandler(itemUriCfg)
|
||||
switch method {
|
||||
case http.MethodGet:
|
||||
g.GET(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodHead:
|
||||
g.HEAD(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodPost:
|
||||
g.POST(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodPut:
|
||||
g.PUT(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodPatch:
|
||||
g.PATCH(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodDelete:
|
||||
g.DELETE(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodOptions:
|
||||
g.OPTIONS(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodTrace:
|
||||
panic(`method Trace is not supported`)
|
||||
default:
|
||||
panic("method " + itemUriCfg.RequestMethod + " is not support")
|
||||
// 一个接口支持注册多种请求方法
|
||||
for _, method := range itemUriCfg.RequestMethod {
|
||||
switch method {
|
||||
case http.MethodGet:
|
||||
g.GET(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodHead:
|
||||
g.HEAD(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodPost:
|
||||
g.POST(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodPut:
|
||||
g.PUT(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodPatch:
|
||||
g.PATCH(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodDelete:
|
||||
g.DELETE(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodOptions:
|
||||
g.OPTIONS(itemUriCfg.Path, handleFunc)
|
||||
case http.MethodTrace:
|
||||
panic(`method Trace is not supported`)
|
||||
default:
|
||||
panic("method " + method + " is not support")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user