julienschmidt / httprouter

A high performance HTTP request router that scales well
https://pkg.go.dev/github.com/julienschmidt/httprouter
BSD 3-Clause "New" or "Revised" License
16.56k stars 1.47k forks source link

how use group router on httprouter? #216

Open runthinker opened 7 years ago

runthinker commented 7 years ago

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

shinriyo commented 7 years ago

@runthinker

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

    v1 := router.Group("/openapi")
    {
        v1.GET("/authapi", middle func)
        v1.GET("/adduser", middle func)
    }
}
runthinker commented 7 years ago

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

Hunsin commented 6 years ago

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.