gRPC request returns a response that missing fields while these fields are not zero-value when debugging

1 week ago 17
ARTICLE AD BOX

Background: A gRPC request from Apifox(a API platform, like postman) sent from local machine to the service also running at local, it's a pageing query for customer_id, here is what response proto looks like and what apifox get

proto:

message ListCustomerIDReply { repeated uint32 list = 1; uint32 total_count = 2; bool has_next_page = 3; }

apifox:

{ "list": [ 15, 14, 13 ] }

Problem: I don't get the last two fields, but when i start debugging it appears they do has value

debugging

and outside this method is proto-generated code, so here is the last place my own code could have reach

outside the method:

func _CustomerService_ListCustomerID_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ListCustomerIDRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { return srv.(CustomerServiceServer).ListCustomerID(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, FullMethod: CustomerService_ListCustomerID_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(CustomerServiceServer).ListCustomerID(ctx, req.(*ListCustomerIDRequest)) } return interceptor(ctx, in, info, handler)

my proto version:

protoc-gen-go v1.31.0 protoc v6.33.2

struct generated:

type ListCustomerIDReply struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields List []uint32 `protobuf:"varint,1,rep,packed,name=list,proto3" json:"list,omitempty"` TotalCount uint32 `protobuf:"varint,2,opt,name=total_count,json=totalCount,proto3" json:"total_count,omitempty"` HasNextPage bool `protobuf:"varint,3,opt,name=has_next_page,json=hasNextPage,proto3" json:"has_next_page,omitempty"` }
Read Entire Article