tag #13
wangjc0216
started this conversation in
Go
tag
#13
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
tag是结构体其中的一个字段。
在使用反射可以动态的给结构体成员赋值,正是因为有 tag,在赋值前可以使用 tag 来决定赋值的动作。比如,官方的 encoding/json 包,可以将一个 JSON 数据 Unmarshal 进一个结构体,此过程中就使用了 Tag, 该包定义一些规则,只要参考该规则设置 tag 就可以将不同的 JSON 数据转换成结构体。
基于 struct 的 tag 特性,有了诸如 json、orm 等等的应用。理解这个可以定义另一种 tag 规则,来处理特有的数据
All reactions