Git Product home page Git Product logo

Comments (6)

maxlevinps avatar maxlevinps commented on September 27, 2024 3

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 .

from go-querystring.

willnorris avatar willnorris commented on September 27, 2024

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.

from go-querystring.

Andrew-M-C avatar Andrew-M-C commented on September 27, 2024

There IS such kind of scenarios. We now have two:

  • 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.
type config struct {
    Username string `sys1:"username"  sys2:"loginname"`
}

However, I prefer passing tag as a runtime parameter instead of pre-binding. Such as:

v, _ := query.ValuesByTag(&conf, "sys1")

from go-querystring.

NilsJPWerner avatar NilsJPWerner commented on September 27, 2024

We have the same use case that would be great to solve using this library.

from go-querystring.

svvitale avatar svvitale commented on September 27, 2024

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.

from go-querystring.

gudvinr avatar gudvinr commented on September 27, 2024

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.

gorilla/schema implements this in exactly the same way using SetAliasTag both in encoder and decoder.

from go-querystring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.