浏览代码

Expose HandlerFunc in RouteInfos (#1272)

Thomas Schaffer 7 年之前
父节点
当前提交
c65e5efc9a
共有 1 个文件被更改,包括 9 次插入6 次删除
  1. 9 6
      gin.go

+ 9 - 6
gin.go

@@ -38,9 +38,10 @@ func (c HandlersChain) Last() HandlerFunc {
 
 
 // RouteInfo represents a request route's specification which contains method and path and its handler.
 // RouteInfo represents a request route's specification which contains method and path and its handler.
 type RouteInfo struct {
 type RouteInfo struct {
-	Method  string
-	Path    string
-	Handler string
+	Method      string
+	Path        string
+	Handler     string
+	HandlerFunc HandlerFunc
 }
 }
 
 
 // RoutesInfo defines a RouteInfo array.
 // RoutesInfo defines a RouteInfo array.
@@ -266,10 +267,12 @@ func (engine *Engine) Routes() (routes RoutesInfo) {
 func iterate(path, method string, routes RoutesInfo, root *node) RoutesInfo {
 func iterate(path, method string, routes RoutesInfo, root *node) RoutesInfo {
 	path += root.path
 	path += root.path
 	if len(root.handlers) > 0 {
 	if len(root.handlers) > 0 {
+		handlerFunc := root.handlers.Last()
 		routes = append(routes, RouteInfo{
 		routes = append(routes, RouteInfo{
-			Method:  method,
-			Path:    path,
-			Handler: nameOfFunction(root.handlers.Last()),
+			Method:      method,
+			Path:        path,
+			Handler:     nameOfFunction(handlerFunc),
+			HandlerFunc: handlerFunc,
 		})
 		})
 	}
 	}
 	for _, child := range root.children {
 	for _, child := range root.children {