您的位置:首页 > 编程语言 > Go语言

go structTag

2018-01-30 18:12 225 查看
go structTag

列子,如下

type Message struct {
Name         string                           `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Hilarity     Message_Humour                   `protobuf:"varint,2,opt,name=hilarity,enum=proto3_proto.Message_Humour" json:"hilarity,omitempty"`
HeightInCm   uint32                           `protobuf:"varint,3,opt,name=height_in_cm,json=heightInCm" json:"height_in_cm,omitempty"`
Data         []byte                           `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
}


解释:
//protobuf、json是是两种不同的struct内容的声明方式后面还可以接其它类型
//protobuf 第一个参数:name的编译以后的类型,第二个参数:声明变量的被编译的顺序,
//第三个参数:opt表示可选,req表示必选
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: