Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

gRPC generated file doesn't have json definition

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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"`
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading