问题
Message user是这样的
message User {
int32 uid = 1;
string username = 2;
string password = 3;
}
生成的go代码是这样的:
type User struct {
Uid int32 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty"`
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
我直接用上述User
存入MySQL会出错,因为XXX_NoUnkeyedLiteral
这些字段不存在,有个解决的办法是我手动改这个生成的代码,忽略这些字段,但不知大家是怎么做的?
当然是写一个新的结构体啊,protoc生成的文件是不建议改的