httprouter icon indicating copy to clipboard operation
httprouter copied to clipboard

how use group router on httprouter?

Open runthinker opened this issue 7 years ago • 3 comments

for example: r2 := r.Group('/openapi',middle func) r3 := r.Group('/authapi',middle func) r3.Get('/adduser',func handle) ....

runthinker avatar Sep 16 '17 15:09 runthinker

@runthinker

func main() {
    router := gin.Default()

    v1 := router.Group("/openapi")
    {
        v1.GET("/authapi", middle func)
        v1.GET("/adduser", middle func)
    }
}

shinriyo avatar Sep 18 '17 14:09 shinriyo

@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))

runthinker avatar Sep 19 '17 02:09 runthinker

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.

Hunsin avatar Nov 15 '17 05:11 Hunsin