代码拉取完成,页面将自动刷新
package xgin
import (
"github.com/gin-gonic/gin"
"net/http"
"path/filepath"
"strings"
)
type RouteInfo struct {
Name string `json:"name"`
Path string `json:"path"`
baseName string
basePath string
}
type RoutesInfo []RouteInfo
type RouterGroup struct {
Name string
Group *gin.RouterGroup
}
var routes RoutesInfo
func Routes(prefix string) RoutesInfo {
// 对数据进行处理
var result RoutesInfo
for _, v := range routes {
if v.Name == "" {
continue
}
path := filepath.Join(v.basePath, v.Path)
if strings.Contains(path, prefix) {
result = append(result, v)
}
}
return result
}
func (info *RouteInfo) BasePath() string {
return info.basePath
}
func (info *RouteInfo) BaseName() string {
return info.baseName
}
func (group *RouterGroup) Handle(httpMethod string, info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
routes = append(routes, RouteInfo{
Name: info.Name,
Path: info.Path,
baseName: group.Name,
basePath: group.Group.BasePath(),
})
return group.Group.Handle(httpMethod, info.Path, handlers...)
}
func (group *RouterGroup) Any(info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
routes = append(routes, RouteInfo{
Name: info.Name,
Path: info.Path,
baseName: group.Name,
basePath: group.Group.BasePath(),
})
return group.Group.Any(info.Path, handlers...)
}
func (group *RouterGroup) POST(info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
return group.Handle(http.MethodPost, info, handlers...)
}
func (group *RouterGroup) GET(info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
return group.Handle(http.MethodGet, info, handlers...)
}
// DELETE is a shortcut for router.Handle("DELETE", path, handle).
func (group *RouterGroup) DELETE(info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
return group.Handle(http.MethodDelete, info, handlers...)
}
// PATCH is a shortcut for router.Handle("PATCH", path, handle).
func (group *RouterGroup) PATCH(info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
return group.Handle(http.MethodPatch, info, handlers...)
}
// PUT is a shortcut for router.Handle("PUT", path, handle).
func (group *RouterGroup) PUT(info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
return group.Handle(http.MethodPut, info, handlers...)
}
// OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).
func (group *RouterGroup) OPTIONS(info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
return group.Handle(http.MethodOptions, info, handlers...)
}
// HEAD is a shortcut for router.Handle("HEAD", path, handle).
func (group *RouterGroup) HEAD(info RouteInfo, handlers ...gin.HandlerFunc) gin.IRoutes {
return group.Handle(http.MethodHead, info, handlers...)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。