TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Small introduction to tags in Go

75 点作者 SerialMiller将近 10 年前

6 条评论

simi_将近 10 年前
This is what I like about Go. This &quot;small introduction&quot; is basically everything there is to know about struct tags.<p>Bonus, Gorethink tags [0] and how we use them at Lavaboom [1].<p>0: <a href="https:&#x2F;&#x2F;github.com&#x2F;dancannon&#x2F;gorethink#encodingdecoding-structs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dancannon&#x2F;gorethink#encodingdecoding-stru...</a><p>1: <a href="https:&#x2F;&#x2F;github.com&#x2F;lavab&#x2F;api&#x2F;tree&#x2F;master&#x2F;models" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lavab&#x2F;api&#x2F;tree&#x2F;master&#x2F;models</a>
MikeKusold将近 10 年前
At GopherCon, Kyle Erf and Sam Helman gave a great talk about struct tags, how some people are currently using them.<p>SourceGraph did a write up that summarized it very nicely. <a href="https:&#x2F;&#x2F;sourcegraph.com&#x2F;blog&#x2F;live&#x2F;gophercon2015&#x2F;123669868275" rel="nofollow">https:&#x2F;&#x2F;sourcegraph.com&#x2F;blog&#x2F;live&#x2F;gophercon2015&#x2F;123669868275</a>
评论 #9924781 未加载
jamesfisher将近 10 年前
Why is this &quot;tag&quot; system considered a good feature? It seems so arbitrary. It&#x27;s used exclusively for reflective logic which should instead be done at compile-time via a macro system or a system like Template Haskell, which would generate instances like `ToJson`&#x2F;`FromJson` for a given struct. As the article mentions, Go tags are similar to Java annotations: a mis-feature motivated by the absence of a macro system.
评论 #9926931 未加载
评论 #9927893 未加载
aikah将近 10 年前
tags are just strings. there is no spec tag whatsoever or syntax that can be validated at compile time.<p>A better solution would have been a proper annotation system that is part of the spec.
评论 #9925085 未加载
quibit将近 10 年前
This 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.
评论 #9924014 未加载
评论 #9926088 未加载
asdfasdfasjkl将近 10 年前
&#x2F;&#x2F; VerifyPassword checks if password is valid and upgrades it if its encrypting scheme was outdated &#x2F;&#x2F; Returns isValid, wasUpdated, error<p>func (a *Account) VerifyPassword(password string) (bool, bool, error) {<p>this is why we need sum types people
评论 #9928232 未加载