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

when use context.Param() to get optional params from url, it will always return a slash #1255

Closed
CodingPapi opened this issue Feb 22, 2018 · 3 comments

Comments

@CodingPapi
Copy link

CodingPapi commented Feb 22, 2018

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

@appleboy
Copy link
Member

router.GET("api/:fixed/:optional", func(context *gin.Context) {
  t1 := context.Param("fixed")
  t2 := context.Param("optional")
})

change *optional to :optional

@CodingPapi
Copy link
Author

CodingPapi commented Feb 24, 2018

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

@CodingPapi
Copy link
Author

:optional is a better way

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

2 participants