What are filtered field tags in Golang structs?

huangapple go评论93阅读模式
英文:

What are filtered field tags in Golang structs?

问题

type User struct {
Id int
Password string filtered:"true"
}

关于filtered:"true"部分的说明。我从未在其他地方见过这个,也找不到规范中的任何相关信息。可能类似于不导出字段吗?

有人有更多信息吗?

英文:
type User struct {
    Id                int
	Password          string `filtered:"true"`
}

Referring to the filtered: "true" part. Never seen this anywhere else, and can't find anything in the spec about it. Presumably it's similar to not exporting a field?

Does anyone have more information?

答案1

得分: 3

在语言中,结构标签没有被赋予特殊的含义,它们是由查找它们的包进行解释的。

在这种情况下,filtered:true 对使用 User 类型的包来说有特定的含义,并根据自己的需要进行处理。这与 encoding/json 中的 json: 标签的工作方式相同。

英文:

There is no special meaning assigned to struct tags by the language, they are interpreted by the package looking for them.

In this case, filtered:true means something to the package that uses the User type, and acts on that however it sees fit. This is the same as how the json: tags work in encoding/json.

huangapple
  • 本文由 发表于 2016年3月16日 02:57:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/36019806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定