It's true that you don't need to add this tags on your Struct, but I do for 2 mainly reasons:
Almost all of my code is form REST/Http Request, so I need to decode the Request's body into a Struck, and having theses tags make the process automatic to me.
And for me is more like a kind of documentation, because I know the fields names in the database so when I look to my Struct it gives me a smallprint of how my data is organized.
One curious thing is, if you use the bson: tag. You don't need to obey the order and neither the names between the Struct and you Collection.
type Hero struct {
Name string
json:"name"
Alias string
json:"alias"
Signed bool
json:"signed"
}
Why i need
this json:name, json:alias, json signed
with my struct value?Hi frindidoy, great question!
It's true that you don't need to add this tags on your Struct, but I do for 2 mainly reasons:
One curious thing is, if you use the
bson:
tag. You don't need to obey the order and neither the names between the Struct and you Collection.Let me know if you still have any doubts about it!