加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

golang structs定义中backtick的用法是什么?

发布时间:2020-12-16 09:42:12 所属栏目:大数据 来源:网络整理
导读:参见英文答案 Strange type definition syntax in Golang (name,then type,then string literal)1答案 type NetworkInterface struct { Gateway string `json:"gateway"` IPAddress string `json:"ip"` IPPrefixLen int `json:"ip_prefix_len"` MacAddress s
参见英文答案 > Strange type definition syntax in Golang (name,then type,then string literal)1答案
type NetworkInterface struct {
    Gateway              string `json:"gateway"`
    IPAddress            string `json:"ip"`
    IPPrefixLen          int    `json:"ip_prefix_len"`
    MacAddress           string `json:"mac"`
    ...
}

我很困惑什么是内容在backtick的功能,如json:“网关”。

它只是评论,像//这是网关?

您可以以标签的形式向Go结构添加额外的元信息。 Here are some examples of use cases。

在这种情况下,json package使用json:“网关”将Gateway的值编码到相应json对象中的关键网关。

例:

n := NetworkInterface{
   Gateway : "foo"
}
json.Marshal(n)
// will output `{"gateway":"foo",...}`

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读