Giter Club home page Giter Club logo

Comments (6)

kisielk avatar kisielk commented on August 22, 2024

It's an implementation detail, so best not to export it. Does RegisterConverter not work for your case?

from schema.

themihai avatar themihai commented on August 22, 2024

I don't think RegisterConverter helps. Decode errors out[0] if the value provided is not struct, isn't it? An alternative would be to provide a new function DecodeValue(valStr string, kind reflect.Kind)reflect.Value which decodes a single value.

[0] https://github.com/gorilla/schema/blob/master/decoder.go#L72

from schema.

kisielk avatar kisielk commented on August 22, 2024

Hm maybe I'm not clear on what you are looking for. You want to decode the values in to a map directly, one which isn't a member of a struct? I'm not sure why you would even need the schema package for that.

from schema.

themihai avatar themihai commented on August 22, 2024

I need to unmarshal a map[string][]string into two variables . One is a struct and the other is of a type supported by schema (bool, int etc) but unknown at compile time. So I use schema.Decoder to unmarshal the map into the struct and then I need to parse the value of the 2nd variable(I know its key) thus the reason why I need the Convertors/parsing function.
Another option is to merge the unknown variable with the struct in a map using reflect (make a new map, copy all the struct fields as keys -> pointers) but Decoder doesn't support maps either(I fail to see the reason why).

    form := r.FormValue()
   var1 := schema.NewDecoder().Decode(val.Interface(), form)

   var2 := schema.Convertors[paramTyp.Elem().Kind()](form.Get(paramName))

from schema.

themihai avatar themihai commented on August 22, 2024

Shortly said schema package has an internal function(convertors) which marshals a string into various types/kinds and I need just that thus the proposal to export it.

from schema.

stale avatar stale commented on August 22, 2024

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

from schema.

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.