相关疑难解决方法(0)

Go中的标签有什么用途?

Go语言规范中,它提到了标签的简要概述:

字段声明后面可以跟一个可选的字符串文字标记,该标记成为相应字段声明中所有字段的属性.标签通过反射界面可见,但否则将被忽略.

// 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"
}
Run Code Online (Sandbox Code Playgroud)

这是一个非常简短的解释IMO,我想知道是否有人可以提供我这些标签的用途?

reflection struct go

364
推荐指数
3
解决办法
8万
查看次数

golang结构定义中反引号的用法是什么?

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吗?

go

105
推荐指数
2
解决办法
4万
查看次数

Golang 结构体中名称和类型后面的字符串是什么?

我正在查看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)

struct go kubernetes-secrets

5
推荐指数
1
解决办法
3084
查看次数

在golang中,"某事"是什么意思

我有这个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读取不起作用.

go

0
推荐指数
1
解决办法
222
查看次数

标签 统计

go ×4

struct ×2

kubernetes-secrets ×1

reflection ×1