保存路由统一注册方法
This commit is contained in:
37
router/group.go
Normal file
37
router/group.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user