Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how use group router on httprouter? #216

Open
runthinker opened this issue Sep 16, 2017 · 3 comments
Open

how use group router on httprouter? #216

runthinker opened this issue Sep 16, 2017 · 3 comments

Comments

@runthinker
Copy link

runthinker commented Sep 16, 2017

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

@shinriyo
Copy link

@runthinker

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

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

@runthinker
Copy link
Author

@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
Copy link

Hunsin commented Nov 15, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants