You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support alternative struct tags (instead of url) #29
We use Gin, and we're looking at using this library. Gin provides a BindQuery method, which decodes query params from a request into a struct, so long as the incoming request matches the expected names, expressed via the struct tag form.
We'd like to be able to use the same struct tags for encoding and decoding. In order to do so, we'd like to be able to configure this library to reflect on a different struct tag during encoding. In our case, we'd like to be able to configure this library to use the same struct tag as Gin, i.e., the form tag.
Would you be open to a PR that implements configurable struct tags?
I'm not sure what the best mechanism would be, perhaps a build flag or ENV_VAR. Any suggestions here would be most welcome.
Is this still a problem for you, or did you end up working around it?
If it's still a desirable feature, does anyone have pointers to examples of other libraries that do this? #15 does provide an implementation, but I just don't think I've ever seen a library that allows customizing struct tags like this, so would love to see any prior art before making any decisions.
Migrate some struct definitions from older ones, such as some struct defined by json tags
Generate some customized tags different from url query for different internal systems. For example, In system A, we use camel style, but some snake style.
Hey @willnorris , we need this feature too, we are are working with gin +go-querystring and we have to tag both form and url in all of our params structs. Specifying custom tag for encoding will reduce chances of bugs when not setting both tags, and improve readability to our code. I hope you can reconsider merging #15 .
We also have a similar use case where we need to form encode a struct that only contains json tags. Unfortunately we do not own the struct definition, and cannot add url tags.
If it's still a desirable feature, does anyone have pointers to examples of other libraries that do this? #15 does provide an implementation, but I just don't think I've ever seen a library that allows customizing struct tags like this, so would love to see any prior art before making any decisions.
Activity
willnorris commentedon Feb 24, 2021
Is this still a problem for you, or did you end up working around it?
If it's still a desirable feature, does anyone have pointers to examples of other libraries that do this? #15 does provide an implementation, but I just don't think I've ever seen a library that allows customizing struct tags like this, so would love to see any prior art before making any decisions.
Andrew-M-C commentedon Jun 15, 2021
There IS such kind of scenarios. We now have two:
jsontagsurlquery for different internal systems. For example, In system A, we use camel style, but some snake style.However, I prefer passing tag as a runtime parameter instead of pre-binding. Such as:
maxlevin-gc commentedon Feb 6, 2022
Hey @willnorris , we need this feature too, we are are working with
gin+go-querystringand we have to tag bothformandurlin all of our params structs. Specifying custom tag for encoding will reduce chances of bugs when not setting both tags, and improve readability to our code. I hope you can reconsider merging #15 .NilsJPWerner commentedon Mar 1, 2022
We have the same use case that would be great to solve using this library.
svvitale commentedon Feb 14, 2023
We also have a similar use case where we need to form encode a struct that only contains
jsontags. Unfortunately we do not own the struct definition, and cannot addurltags.gudvinr commentedon Aug 28, 2023
gorilla/schema implements this in exactly the same way using SetAliasTag both in encoder and decoder.