httprouter
httprouter copied to clipboard
how use group router on httprouter?
for example: r2 := r.Group('/openapi',middle func) r3 := r.Group('/authapi',middle func) r3.Get('/adduser',func handle) ....
@runthinker
func main() {
router := gin.Default()
v1 := router.Group("/openapi")
{
v1.GET("/authapi", middle func)
v1.GET("/adduser", middle func)
}
}
@shinriyo thank you! i use this method: func ValidToken(next httprouter.Handle) httprouter.Handle{ return func(....) .... } r.Get("/openapi/adduser",handle func) r.Get("/authapi/adduser",ValidToken(handle func))
You can check the pull request #89 , It has a good implementation of sub routing.
Or, check my Gist, which was inspired by the former one and gin.