0

I'm trying to generate Go file from proto file but it doesn't have json definition in the method's input definition. Should I add the json definition by myself or there were something wrong with my script. Thank you, I sincerely appreciate your help.

Proto file

message RateRequest {
    string Base = 1;
    string Destination = 2;
}

Generated file

type RateRequest struct {
    state         protoimpl.MessageState
    sizeCache     protoimpl.SizeCache
    unknownFields protoimpl.UnknownFields

    //No json definition here
    Base        string `protobuf:"bytes,1,opt,name=Base,proto3" json:"Base,omitempty"`
    Destination string `protobuf:"bytes,2,opt,name=Destination,proto3" json:"Destination,omitempty"`
}

Protoc script

protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
protos/currency.proto

grpcurl

grpcurl --plaintext -d '{Base: "GBP", Destination: "USD"}' localhost:9092 Currency.GetRate
// Error invoking method "Currency.GetRate": error getting request data: message type RateRequest has no known field named base

1 Answer 1

0

Since the error is

error getting request data: message type RateRequest has no known field named base

And the json is

json:"Base,omitempty"`

Then it seems it's looking for the wrong field, it should be

json:"base,omitempty"`
2
  • 1
    Thank you I ran grpcurl with grpcurl --plaintext -d '{"Base":"GBP", "Destination":"USD"}' localhost:9092 Currency.GetRate and it worked perfectly!
    – BlackLotus
    Commented Dec 19, 2021 at 16:50
  • Awesome, glad it worked :)
    – Wolfgang
    Commented Dec 19, 2021 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.