Small introduction to tags in Go
machiel.me
Small introduction to tags in Go
1–10 of 17 posts
Re: Small introduction to tags in Go
#2Re: Small introduction to tags in Go
#3Bonus, Gorethink tags [0] and how we use them at Lavaboom [1].
0: https://github.com/dancannon/gorethink#encodingdecoding-stru...
Re: Small introduction to tags in Go
#4This should be handy for frameworks to do their own logic, but I would get very annoyed if I had to read code that was cluttered with tags.
That aside, tags are currently in use in several ORM frameworks with a fair amount of success.
Re: Small introduction to tags in Go
#5SourceGraph did a write up that summarized it very nicely. https://sourcegraph.com/blog/live/gophercon2015/123669868275
Re: Small introduction to tags in Go
#6A better solution would have been a proper annotation system that is part of the spec.
Re: Small introduction to tags in Go
#7At GopherCon, Kyle Erf and Sam Helman gave a great talk about struct tags, how some people are currently using them. SourceGraph did a write up that summarized it very nicely. https://sourcegraph.com/blog/live/gophercon2015/123669868275
Re: Small introduction to tags in Go
#8tags are just strings. there is no spec tag whatsoever or syntax that can be validated at compile time. A better solution would have been a proper annotation system that is part of the spec.
Spent a whole day trying to figure out why only the first tag in the struct was 'active':
Name string `xml:"name", db:"name"` //
The answer was, going from memory, I added a comma (,) between the tags. Should have been: Name string `xml:"name" db:"name"`
Stupid simple mistake, but really hard to track down. There was no compiler error, the second tag failed silently, and the first tag worked, so it was really hard to find the bad code.That along with my favorite: quote-wars. Many-a-time did I forget the quotes on the tag itself only to have it fail (without warning again...):
Name string `xml:name db:"name"` //Re: Small introduction to tags in Go
#9tags are just strings. there is no spec tag whatsoever or syntax that can be validated at compile time. A better solution would have been a proper annotation system that is part of the spec.
This is the one problem. Spent a whole day trying to figure out why only the first tag in the struct was 'active': Name string `xml:"name", db:"name"` // The answer was, going from memory, I added a comma (,) between the tags. Should have been: Name string `xml:"name" db:"name"` Stupid simple mistake, but really hard to track down. There was no compiler error, the second tag failed silently, and the first tag worked,…
Re: Small introduction to tags in Go
#10tags are just strings. there is no spec tag whatsoever or syntax that can be validated at compile time. A better solution would have been a proper annotation system that is part of the spec.
This is the one problem. Spent a whole day trying to figure out why only the first tag in the struct was 'active': Name string `xml:"name", db:"name"` // The answer was, going from memory, I added a comma (,) between the tags. Should have been: Name string `xml:"name" db:"name"` Stupid simple mistake, but really hard to track down. There was no compiler error, the second tag failed silently, and the first tag worked,…