Comments (10)
This is not undefined behavior. You'll always get the first value from the raw query.
There should be a way to specify other behaviors, though.
from schema.
Ah - because parsing the url results in an ordered array, right.
Seems to me like the sort of thing that results in confused developers 6 months down the track if multiple params are involved:
eg given a querystring like ?api_query=get&api_key=af4eb2&filter=valid&order=desc&api_key=4bcfe13b
it's hard to spot that changing the api_key parameter at the end isn't going to change what the server sees.
from schema.
Most request wrappers get the first value from the query/form when a single value is needed, but I saw some that get the last (werkzeug in Python if I'm not mistaken).
You need to be careful when building queries. Not hard to normalize the one from your example.
from schema.
In eg sinatra/rails you get a string if there's one and an array if there's multiple values, which lets you access each value.
If I'm writing an API that expects a parameter once and someone specifies it more than once, I'm going to assume they made a mistake.
I think it's better to return an error message in that situation rather than try to guess which one they meant, particularly if there isn't an agreed standard on how to make that decision.
from schema.
Maybe it would be possible to do something similar to the Header type in net/http: http://golang.org/pkg/net/http/#Header
The type itself is a map[string][]string, so it has all of the possible values available for the key if you want to get them directly from the map. The type's methods treat it as if it only has one value for each key.
from schema.
That's cool, I hadn't looked at that type before.
from schema.
But doesn't the URL package already expose url.Query() as type url.Values map[string][]string
from schema.
Right, nevermind that, I see what is happening now. I think different people will want different behaviours in this case so the only solution is to make it configurable, it doesn't seem like there's a good default, which I guess is the whole reason this issue even exists.
from schema.
I think the current default is good. But I'd like that the API allowed you to override it, by implementing some kind of decoding interface.
An old idea I have is to implement something similar to the PropertyLoadSaver in App Engine's datastore, except that just for loading values (so PropertyLoader or something). This could also be a hook for validation (which is something I find particularly hard to do in Go because doing it manually is better than any helper API). Just for reference: https://developers.google.com/appengine/docs/go/datastore/reference#PropertyLoadSaver
It's not clear to me that this would fit, but the gist is that I want to make it more extendable somehow, keeping the convenience of sensible defaults like it is now.
from schema.
Right now we're loading the last value and I think it's going to stay that way.
from schema.
Related Issues (20)
- [feature] default values for scheme struct fields HOT 13
- [feature] Use json struct tags if wanted HOT 2
- [question] "+" symbol HOT 6
- ⚠️ The Gorilla Toolkit is Looking for a New Maintainer HOT 10
- [bug] Unstable decoding of different keys that are case-folded to the same value HOT 1
- Not checking for nil might lead to nil pointer dereference HOT 4
- [question] Error converting into []byte or []uint8 HOT 2
- [bug] schema: converter not found for Page, when the struct name is same with field name. HOT 6
- [question] Why can't Encoder check and call fmt.Stringer.String() on element automatically? HOT 1
- [BUG] v1.2.0 Cannot decode into slice of strings HOT 2
- [bug] need to skip unexported field HOT 2
- [BUG] Nested struct with required field is not failing on decode HOT 1
- [FEATURE] Documentation HOT 4
- [Question] Is ignoring mismatched slice element types intended behavior? HOT 3
- [BUG] panic in 1.3.0 HOT 6
- [Question] Form encoding/decoding ignores slice of struct HOT 4
- [BUG] Slice encoding drops empty values rather than encoding them as `nil` or default HOT 3
- [FEATURE] Use omitempty by default HOT 4
- [BUG] nil pointer values are encoded as "null" and not decodable HOT 1
- Question May I open an PR to refactor or organize the test code in decoder_test.go? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schema.