feat(http): 启动时打印路由表并合并请求方法
This commit is contained in:
1 parent
90d47c0152
commit
cfed548cbc
7 files changed
+252
-7
No files matched your search
+8
-6
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"path"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -29,11 +30,12 @@ type Metadata struct {
|
||||
}
|
||||
|
||||
type route struct {
|
||||
meta Metadata `dc:"不可变路由元数据"`
|
||||
handlers []gin.HandlerFunc `dc:"启动时装配的路由处理链"`
|
||||
input reflect.Type `dc:"普通 Controller 的 Form 类型,原生路由为空"`
|
||||
output reflect.Type `dc:"普通 Controller 的公开结果类型,原生路由为空"`
|
||||
security string `dc:"Meta 声明的文档安全要求,不执行认证"`
|
||||
handlerName string `dc:"Controller 业务方法名,原生路由从处理函数解析"`
|
||||
meta Metadata `dc:"不可变路由元数据"`
|
||||
handlers []gin.HandlerFunc `dc:"启动时装配的路由处理链"`
|
||||
input reflect.Type `dc:"普通 Controller 的 Form 类型,原生路由为空"`
|
||||
output reflect.Type `dc:"普通 Controller 的公开结果类型,原生路由为空"`
|
||||
security string `dc:"Meta 声明的文档安全要求,不执行认证"`
|
||||
}
|
||||
|
||||
// TrustedField 从可信认证上下文读取一个公共字段,不读取客户端原始输入。
|
||||
@@ -97,7 +99,7 @@ func (s *Server) Group(prefix string, middleware []gin.HandlerFunc, controllers
|
||||
verb = strings.ToUpper(strings.TrimSpace(verb))
|
||||
handlers := append([]gin.HandlerFunc(nil), middleware...)
|
||||
handlers = append(handlers, handler)
|
||||
planned = append(planned, route{meta: Metadata{Method: verb, Path: path.Join("/", prefix, meta.Tag.Get("path")), Summary: meta.Tag.Get("summary"), Tag: meta.Tag.Get("tag")}, handlers: handlers, input: formType, output: signature.Out(0), security: meta.Tag.Get("security")})
|
||||
planned = append(planned, route{handlerName: runtime.FuncForPC(value.Type().Method(i).Func.Pointer()).Name(), meta: Metadata{Method: verb, Path: path.Join("/", prefix, meta.Tag.Get("path")), Summary: meta.Tag.Get("summary"), Tag: meta.Tag.Get("tag")}, handlers: handlers, input: formType, output: signature.Out(0), security: meta.Tag.Get("security")})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||