Open orenl opened 3 weeks ago
json
json
is intentional. we are relying on the same tag that people are already familiar with.
this is natural choice as it follows notation how people are declaring field names for JSON for structs. this reduces cognitive load and allows easy learning. this choice also emphasises, that our concern here is encoding/decoding, and nothing else, which makes limited scope of this tool, which is also beneficial. in fact, I would rather raise proposal to official Go language to include this as official Go language notation.
conflicts with other json tags
best I know, json comment tags can not be used in const nor var declaration. the only place standard Go (and any 3rd party packages I know) are using json tags so far are in struct declaration. this AST tool scans json tags only for const and var declarations. thus no conflicts should happen.
issue is open to collect feedback from others.
The use of
json:"..."
as a tag in the comment is too generic. It may conflict with casual comments elsewhere in the code (in const or var). Consider renaming toenum:"..."
.Note that once #24 get fixed, such conflicts should not happen, since this would be confined to the designated type; Nevertheless, IMO
enum:"..."
would still be more precise choice.For example: