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

Support for gin query param unmarshaling? #82

Open
APILLSBURY opened this issue May 8, 2024 · 1 comment
Open

Support for gin query param unmarshaling? #82

APILLSBURY opened this issue May 8, 2024 · 1 comment

Comments

@APILLSBURY
Copy link

Gin just added a new interface called BindUnmarshaler that allows types to define a UnmarshalParam method which lets them be used as query parameters.

Implementing this would allow binding KSUID API query params like this:

type queryParams struct {
  ID KSUID `form:"id"`
}

route.GET("/test", func(ctx *gin.Context) {
  var params queryParams{}
  _ = ctx.BindQuery(&params)
 entity, err := GetEntity(params.ID)
 ...
})

I think all that is necessary is adding this method:

func (i *KSUID) UnmarshalParam(s string) error {
	return i.UnmarshalText([]byte(s))
}

I'm happy to open a PR for it if that would be helpful.

@APILLSBURY
Copy link
Author

Alternatively, adding an UnmarshalJSON method would solve this

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

1 participant