-
Notifications
You must be signed in to change notification settings - Fork 84
Introduce a FieldMapFromStruct() to avoid repetitions? #18
Comments
@wmark I've taken a similar approach in sqldecoder. Though, I started with reflection based binding, and then added reflection-less. The advantage of such an approach, obviously, is that support "just works". But I do think it would be a strike against "reflectionless". Maybe the project would change to "reflection optional"... |
That's a big struct! I can understand wanting to eliminate the repetition of the field names. Though using tags could avoid that repetition, it introduces new repetition, namely the key (probably Also, how would custom field binders be defined in field tags? |
If there were no The result is a FieldMap as usual. You could change fields after auto-generation. If this is a long structure, then you certainly don't want to see another one I've stumbled upon in a project using a columnar store — it has 519 fields, and API calls to expose all. Easily manageable using Python. I am currently looking into @bhcleek's sqldecoder and ffjson for inspirations to come up for a solution with a one-time cost. BTW: |
Cool, good luck with that! However I am, at this point, a little uncomfortable with introducing reflection into this package. Maybe there could be a codegen tool like JSON-to-Go that could help with generating a FieldMap for such large structs. |
+1 for code generation.
|
Now that Go 1.4 is out, perhaps it would be better to provide a generator? |
What can we add to avoid repetitions such as this?
https://gist.github.com/wmark/73ee2abe30e13af93a18#file-mailgun-go-L3-L57
A
FieldMapFromStruct()
could use reflection to generate the FieldMap from tags(?). Because this has to be done once only, for example during the module'sinit()
I believe it wouldn't count towards the claim Binding was »reflectionless«.The text was updated successfully, but these errors were encountered: