我有一个原始文件:
syntax = "proto3";
package main;
message Client {
int32 Id = 1;
string Name = 2;
string Email = 3;
}
编译后的Client结构如下:
type Client struct {
Id int32 `protobuf:"varint,1,opt,name=Id,proto3" json:"Id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty"`
Email string `protobuf:"bytes,3,opt,name=Email,proto3" json:"Email,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
当我尝试Client像下面这样初始化此结构时:
client := &Client{123, "John", "john@aol.com"}
我收到了构建错误:too few values in struct initializer。我发现了一种通过增加来解决它XXX_NoUnkeyedLiteral,XXX_unrecognized,XXX_sizecache。我不知道这些是什么,并且想知道这是否是正确的方法:
client := &Client{123, "John", "john@aol.com", struct{}{}, []byte{}, int32(0)}
aluckdog
慕容708150
相关分类