在Go语言规范中,它提到了标签的简要概述:
字段声明后面可以跟一个可选的字符串文字标记,该标记成为相应字段声明中所有字段的属性.标签通过反射界面可见,但否则将被忽略.
Run Code Online (Sandbox Code Playgroud)// A struct corresponding to the TimeStamp protocol buffer. // The tag strings define the protocol buffer field numbers. struct { microsec uint64 "field 1" serverIP6 uint64 "field 2" process string "field 3" }
这是一个非常简短的解释IMO,我想知道是否有人可以提供我这些标签的用途?
type NetworkInterface struct {
Gateway string `json:"gateway"`
IPAddress string `json:"ip"`
IPPrefixLen int `json:"ip_prefix_len"`
MacAddress string `json:"mac"`
...
}
Run Code Online (Sandbox Code Playgroud)
我很困惑什么是反引号内容的功能,比如json:"gateway"
.
这只是评论//this is the gateway
吗?
我正在查看https://godoc.org/k8s.io/api/core/v1#Secret
type Secret struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Data contains the secret data. Each key must consist of alphanumeric
// characters, '-', '_' or '.'. The serialized form of the secret data is a
// base64 encoded string, representing the arbitrary (possibly non-string)
// data value here. Described in https://tools.ietf.org/html/rfc4648#section-4
// +optional
Data map[string][]byte `json:"data,omitempty" protobuf:"bytes,2,rep,name=data"`
// stringData allows specifying non-binary secret data in string form. …
Run Code Online (Sandbox Code Playgroud) 我有这个XML阅读器结构:
type Recurlyservers struct {
XMLName xml.Name `xml:"servers"`
Version string `xml: "version,attr"`
Svs []server `xml: "server"`
Description string `xml:",innerxml"`
}
Run Code Online (Sandbox Code Playgroud)
这样做有什么意思xml:"servers"
或xml: "version,attr"
?我不知道这是什么.我想在谷歌搜索,但我不知道它的名字.它是什么?如果没有这个,我可以使用标准结构吗?因为没有这个,XML读取不起作用.