Golang 结构体标签(Struct tag )
在Go语言当中,好多功能都使用了结构体标签。主要应用在encoding/json和encoding/xml之中。那么我们先用Json的使用做一个例子。首先创建一个结构体。
1 2 3 4 5 6 7 8 |
type User struct { Id int `json:"id"` Name string `json:"name"` Bio string `json:"about,omitempty"` Active bool `json:"active"` Admin bool `json:"-"` CreatedAt time.Time `json:"created_at"` } |
对于结构体的标签就是紧跟成员定义后,类型后面的那串字符串,[……]