We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用go-micro版本号:v2.5.0 micro的版本号:v2.5.0 micro api设置: MICRO_API_ENABLE_RPC=true proto文件: type AdminListResponse struct { //@inject_tag: json:"count" // google.protobuf.Int32Value count = 1 ; Count int32 protobuf:"varint,1,name=count,proto3" json:"count"//用户信息 //@inject_tag: json:"accounts" Accounts []*AdminInfoprotobuf:"bytes,2,rep,name=accounts,proto3" json:"accounts"XXX_NoUnkeyedLiteral struct{} json:"-"XXX_unrecognized []byte json:"-"XXX_sizecache int32 json:"-" } 手动删除omitempty后空字段还是不返回默认值
type AdminListResponse struct { //@inject_tag: json:"count" // google.protobuf.Int32Value count = 1 ; Count int32
//用户信息 //@inject_tag: json:"accounts" Accounts []*AdminInfo
XXX_NoUnkeyedLiteral struct{}
XXX_unrecognized []byte
XXX_sizecache int32
}
handler : `func (h *Admin) List(ctx context.Context, req *accountpb.AdminListRequest, rsp *accountpb.AdminListResponse) error { var ( //err error count int32 ) //if rsp.Accounts, count, err = h.accountCore.AdminList(req.GetPage(), req.GetLimit(), req.GetSort(), req.GetWhere()); err != nil { // return err //}
//rsp.Count = &wrappers.Int32Value{Value: count} rsp.Count = count return nil
}`
看源码:go-micro/v2/server/grpc中jsonpb默认设置不返回字段 var jsonpbMarshaler = &jsonpb.Marshaler{ EnumsAsInts: false, EmitDefaults: false, OrigName: true, } 我应该如何设置才能返回空字段为默认类型
The text was updated successfully, but these errors were encountered:
可以使用grpc.Codec方法将默认的编码器覆盖掉Server中的对应格式的Codec,比如:
srv.Server().Init(serverGRPC.Codec("application/json", &jsonCodec{}))
见:https://github.com/micro-in-cn/tutorials/tree/master/examples/grpc/codec
Sorry, something went wrong.
No branches or pull requests
使用go-micro版本号:v2.5.0 micro的版本号:v2.5.0
micro api设置: MICRO_API_ENABLE_RPC=true
proto文件:
type AdminListResponse struct { //@inject_tag: json:"count" // google.protobuf.Int32Value count = 1 ; Count int32
protobuf:"varint,1,name=count,proto3" json:"count"//用户信息 //@inject_tag: json:"accounts" Accounts []*AdminInfo
protobuf:"bytes,2,rep,name=accounts,proto3" json:"accounts"XXX_NoUnkeyedLiteral struct{}
json:"-"XXX_unrecognized []byte
json:"-"XXX_sizecache int32
json:"-"}
手动删除omitempty后空字段还是不返回默认值
handler :
`func (h *Admin) List(ctx context.Context, req *accountpb.AdminListRequest, rsp *accountpb.AdminListResponse) error {
var (
//err error
count int32
)
//if rsp.Accounts, count, err = h.accountCore.AdminList(req.GetPage(), req.GetLimit(), req.GetSort(), req.GetWhere()); err != nil {
// return err
//}
}`
看源码:go-micro/v2/server/grpc中jsonpb默认设置不返回字段
var jsonpbMarshaler = &jsonpb.Marshaler{
EnumsAsInts: false,
EmitDefaults: false,
OrigName: true,
}
我应该如何设置才能返回空字段为默认类型
The text was updated successfully, but these errors were encountered: