These are chat archives for gin-gonic/gin

29th
May 2017
Yang Luo
@hsluoyz
May 29 2017 05:16
Could anyone help me here?
I just want to return HTTP 200 for any requests, but I didn't find a way
Here's the current way, I have to manually return 200 for any individual path
router.Any("/dataset1/resource1", func(c *gin.Context) {
    c.Status(200)
})
router.Any("/dataset1/resource2", func(c *gin.Context) {
    c.Status(200)
})
Thomas Boerger
@tboerger
May 29 2017 06:02
You have to define a name how to access the wildcard path, so just define any name after the star
Eason Lin
@easonlin404
May 29 2017 06:11
just like
router.Any("/dataset1/:resource", func(c *gin.Context) {
        c.Status(200)
})
Yang Luo
@hsluoyz
May 29 2017 06:27
Hi, I don't really care about how to access the input args in the path
I'm writting a test for the auth plugin, I only need to let all requests return HTTP 200 with one call
Thomas Boerger
@tboerger
May 29 2017 06:28
Than just write any string behind the star
Yang Luo
@hsluoyz
May 29 2017 06:28
So no matter what input args are passed in, I don't read them, and I always return the 200 status.
Thomas Boerger
@tboerger
May 29 2017 06:29
You are not forced to use this name
Just the router works like that
Eason Lin
@easonlin404
May 29 2017 06:32
router.Any("/*anypath", func(c *gin.Context) {
        c.Status(200)
})
Thomas Boerger
@tboerger
May 29 2017 06:32
Exactly like that
Yang Luo
@hsluoyz
May 29 2017 06:33
Yeah, this is what I want
Thomas Boerger
@tboerger
May 29 2017 06:33
But you can prefix the wildcard however you want
anypath is the name in that case, and you can ignore it in your case within the handler
Writing code on mobile sucks :P
Eason Lin
@easonlin404
May 29 2017 06:35
:smile:
Yang Luo
@hsluoyz
May 29 2017 06:36
It's a llittle hard for me to understand, because for me, it usually means any paths ending with "anypath"
Maybe regex is more understandable
Thanks for all your help :smile:
Thomas Boerger
@tboerger
May 29 2017 06:36
No, it is anything and you can optionally access it by anypath parameter name
It should work like that for any framework using httprouter
Yang Luo
@hsluoyz
May 29 2017 06:40
Yeah, I'm quite new to web dev, don't know httprouter before.
Glad to finally know the grammar about path matching :)