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

Decode to maps #24

Closed
chrneumann opened this issue Apr 15, 2014 · 6 comments
Closed

Decode to maps #24

chrneumann opened this issue Apr 15, 2014 · 6 comments

Comments

@chrneumann
Copy link

If you know your fields (and their types) only at runtime, there is no way to decode values to them. Structs have to be defined at compile time.

A possible solution would be to support maps as target values. For example:

values := map[string][]string{
    "Name":  {"John"},
    "Age": {"55"},
}
person := make(map[string]interface{})
person["Name"] = new(string)
person["Age"] = new(int)
decoder := schema.NewDecoder()
decoder.Decode(person, values)

There could also be support for nested maps, but I guess it would be ok to just support flat maps with fields like "nested.key".

Other ideas?

@yodaiken
Copy link

Support for nested maps, at least, should definitely be included—since we can already support arrays with arr=...&arr=... etc, we should similarly be able to use maps like m.Key=1&m.Key2=2 (where m is map[string]int).

@kisielk
Copy link
Contributor

kisielk commented Aug 11, 2015

I agree this would be a good feature. Unfortunately I don't have time to work on this at the moment, marking as HelpWanted.

@stale
Copy link

stale bot commented Dec 9, 2018

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.

@stale stale bot added the stale label Dec 9, 2018
@FX-HAO
Copy link

FX-HAO commented Dec 10, 2018

Any progress?

@stale stale bot removed the stale label Dec 10, 2018
@stale
Copy link

stale bot commented Feb 8, 2019

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.

@zhangguanzhang
Copy link

Any progress?

have you to resolve this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants