router.GET("api/:fixed/*optional", func(context *gin.Context) {
t1 := context.Param("fixed")
t2 := context.Param("optional")
})
curl http://127.0.0.1:8000/api/user/123
t1 will be "user"
t2 will be "/123"
Is this a bug?
Thank you for any reply
router.GET("api/:fixed/:optional", func(context *gin.Context) {
t1 := context.Param("fixed")
t2 := context.Param("optional")
})
change *optional
to :optional
@appleboy Thank you for ur reply.
I do know use :optional can get the param value that without a slash, but why there should be a "/" when get an optional param? Is there any way to get optional param without that "/" ? Thank you for your kindness!
:optional is a better way
Most helpful comment
change
*optional
to:optional