10.4 带标签的结构体
...小于 1 分钟
10.4 带标签的结构体
标签(tag): 附属于字段的字符串,只能通过reflect包访问。
type TagType struct {
	f1 int  "Field01"
	f2 bool "Field02"
}
func structag() {
	tt := TagType{}
	refTag(tt, 0)
	refTag(tt, 1)
}
func refTag(tt TagType, i int) {
	ttType := reflect.TypeOf(tt)
	f := ttType.Field(i)
	fmt.Println(f.Tag)
}
Field01
Field02
 Powered by  Waline  v2.15.2
