@@ -18,8 +18,12 @@ import (
1818"github.com/gin-gonic/gin/binding"
1919)
2020
21+ // nolint
2122var (
22- rootRouterFns []func (engine * gin.Engine ) // root routing group, used by rpc gateway
23+ apiV1RouterFns_pbExample []func (prePath string , engine * gin.RouterGroup ) // group router functions
24+ // if you have other group routes you can define them here
25+ // example:
26+ // myPrePathRouterFns []func(prePath string, engine *gin.RouterGroup)
2327)
2428
2529// NewRouter_pbExample create a new router
@@ -76,10 +80,20 @@ func NewRouter_pbExample() *gin.Engine { //nolint
7680// access path /apis/swagger/index.html
7781swagger .CustomRouter (r , "apis" , docs .ApiDocs )
7882
79- // registration/Prefix Routing Groups
80- for _ , fn := range rootRouterFns {
81- fn (r )
82- }
83+ // register routers, middleware support
84+ registerRouters_pbExample (r , "/api/v1" , apiV1RouterFns_pbExample )
85+ // if you have other group routes you can add them here
86+ // example:
87+ // registerRouters(r, "/myPrePath", myPrePathRouterFns, middleware.Auth())
8388
8489return r
8590}
91+
92+ // nolint
93+ func registerRouters_pbExample (r * gin.Engine , prePath string ,
94+ routerFns []func (prePath string , engine * gin.RouterGroup ), handlers ... gin.HandlerFunc ) {
95+ rg := r .Group (prePath , handlers ... )
96+ for _ , fn := range routerFns {
97+ fn (prePath , rg )
98+ }
99+ }
0 commit comments