保存路由统一注册方法

This commit is contained in:
2025-01-27 19:46:34 +08:00
parent 851de1b3ef
commit b408076fa7
5 changed files with 207 additions and 7 deletions

37
router/group.go Normal file
View File

@ -0,0 +1,37 @@
// Package router ...
//
// Description : router ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-01-27 19:33
package router
import (
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
// Group 注册接口路由
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 19:35 2025/1/27
func Group(router *gin.Engine, routerPrefix string, middlewareList []gin.HandlerFunc, cList ...any) error {
g := router.Group(routerPrefix)
g.Use(middlewareList...)
cParser := controller{}
for _, c := range cList {
urlTable := cParser.Parse(c)
for _, itemUriCfg := range urlTable {
method := strings.ToUpper(itemUriCfg.Method)
switch method {
case http.MethodGet:
g.HEAD(itemUriCfg.Path)
}
}
}
return nil
}