Skip to content
New issue

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

protobuf type int64 not match to response #2255

Closed
czyt opened this issue Aug 4, 2022 · 1 comment
Closed

protobuf type int64 not match to response #2255

czyt opened this issue Aug 4, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@czyt
Copy link
Contributor

czyt commented Aug 4, 2022

define a service

// 测试信息
  rpc GetTest(google.protobuf.Empty) returns(TestReply){
    option (google.api.http) = {
      get: "/v1/test"
    };

proto type

message TestReply{
  int64  count = 1;
  message TestPayload{
    int32  age = 1;
    int32 height =2;
  }
  TestPayload payload = 2;
}

the logic at service

func (a TestService) GetTest(context.Context, *emptypb.Empty) (*v1.TestReply, error) {
	return &v1.TestReply{
		Count: 11,
		Payload: &v1.TestReply_TestPayload{
			Age:    22,
			Height: 111,
		},
	}, nil
}

and call from url /v1/test get response

{
    "count": "11",
    "payload": {
        "age": 22,
        "height": 111
    }
}{
    "count": 11,
    "payload": {
        "age": 22,
        "height": 111
    }
}

the count feild was not right,should be int64 rather than string,then I change the count type to int32

message TestReply{
  int32  count = 1;
  message TestPayload{
    int32  age = 1;
    int32 height =2;
  }
  TestPayload payload = 2;
}

response is return as expect

{
    "count": 11,
    "payload": {
        "age": 22,
        "height": 111
    }
}
@czyt czyt added the bug Something isn't working label Aug 4, 2022
@czyt
Copy link
Contributor Author

czyt commented Aug 4, 2022

@czyt czyt closed this as completed Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant