Open elv-gilles opened 2 months ago
For case 1, we currently document on JoinOptions
:
Properties set in later options override the value of previously set properties.
but we can make this more explicit elsewhere in the documentation.
If this does get merged into the stdlib, one could imagine a go vet
check for obviously incompatible sets of provided options.
The downside of case 2 is that we would need to return an error in more cases where we take in ...Option
. For example, NewEncoder
, NewDecoder
, Encoder.Reset
and Decoder.Reset
would all need to return an error now.
The downside of case 3 is that it complicates what JoinOpions
means for different option parameters. Always overriding is a relatively simple rule, while merging under some special cases can get confusing.
Looks good, I guess (now - that I know - that seems obvious :-)
I wanted to install multiple unmarshalers and wrote the wrong code below:
This code returns with no error, but the first unmarshalers is ignored.
Instead, after navigating in the source code of
json-experiment
, I discovered I should have written:Looking at the code, I also see that options are merged through
*Struct.Join
.I think it's currently easy to be tripped and (at least) one of the below - in order of increased preference - would be of interest:
UnmarshalDecode
orOptions
to prominently say that only the last option of a given kind will be used (if that comment exists I missed it), and/or*Struct.Join
return an error in case where an option would overwrite a previously set one, and/or*Struct.Join
handle such case and do whatNewUnmarshalers
does (for marshalers/unmarshalers)