type Config struct {
CommitIndex uint64 `json:"commitIndex"`
// TODO decide what we need to store in peer struct
Peers []*Peer `json:"peers"`
}
我知道前两列是什么,但是 json:"commitIndex"
是什么?
最佳答案
称为结构标签,可以使用reflect
解析。在运行时打包。
来自 https://golang.org/ref/spec#Struct_types :
A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration.
The tags are made visible through a reflection interface and take part in type identity for structs but are otherwise ignored.
关于go - Go 结构字段的第三个参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25497375/