英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论