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

Golang中的奇怪类型定义语法(name,then type,then string litera

发布时间:2020-12-16 19:16:49 所属栏目:大数据 来源:网络整理
导读:我一直在试图找出如何使用mgo(MongoDB驱动程序Go),我遇到了这个struct声明: type Something struct { Id bson.ObjectId "_id,omitempty" Name string} 我不太了解第一个元素(Id)的语法。我知道它被声明为类型bson.ObjectId,但是在那里的字符串文字是什么
我一直在试图找出如何使用mgo(MongoDB驱动程序Go),我遇到了这个struct声明:
type Something struct {
    Id bson.ObjectId "_id,omitempty"
    Name string
}

我不太了解第一个元素(Id)的语法。我知道它被声明为类型bson.ObjectId,但是在那里的字符串文字是什么?

我的问题不在于mgo驱动程序的功能,
但是关于这个奇怪的< name> <类型> < string_literal>句法。

我在Go规格上找不到任何东西,我也不知道如何google这个。

这在 language specification的 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
07002 but are otherwise ignored.

// 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"
}

(编辑:李大同)

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

    推荐文章
      热点阅读