1

Prot3 documentation says that by default JSON printer should convert the field name to lowerCamelCase and use that as the JSON name, but I did not observe this in my files:

Lng float32 `protobuf:"fixed32,1,opt,name=Lng,proto3" json:"Lng,omitempty"`
Lat float32 `protobuf:"fixed32,2,opt,name=Lat,proto3" json:"Lat,omitempty"`
message Coordinate {
    float Lng = 1;
    float Lat = 2;
}

Is there an explicit syntax that would do this? I am using protoc-gen-go v1.25.0 and protoc v3.13.0

dclipca
  • 1,739
  • 1
  • 16
  • 51

1 Answers1

1

I have the same problem with my Protos. so I found the solution is in the name of variables, you should change your proto message variables to this :

message Coordinate {
    float lng = 1;
    float lat = 2;
}

the protobuf generates this :

Lng float32 `protobuf:"fixed32,1,opt,name=lng,proto3" json:"lng,omitempty"`
Lat float32 `protobuf:"fixed32,2,opt,name=lat,proto3" json:"lat,omitempty"`

if you have a multi-word variable, you should change it to this:

    float location_lat = 1;

so the generated result will be :

LocationLat float32 `protobuf:"fixed32,1,opt,name=location_lat,proto3" json:"location_lat,omitempty"`
ttrasn
  • 4,322
  • 4
  • 26
  • 43
  • 1
    This works. I did not use this because I presumed that then the Go variables would be lowercase and therefore not exported. It is not the case as I see. – dclipca Sep 23 '20 at 17:19