Open zj8487 opened 5 years ago
What command did you use to generate your golang files from the proto definitions?
@RyanBeatty Thank you very much. The command i use to generate golang files from the proto definitions as follow:
grpc-tools/bin/protoc --gogoslick_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types,plugins=grpc:pb/golang --proto_path=message message/recruit/*.proto
Hey. I don't think I am going to add this extension as an option as the current tag options allows one to do what you are asking for with the help of a vanity binary. Here is an example:
https://github.com/jmarais/protobuf/blob/jsoncasevanity/protoc-gen-gojsoncase/main.go
As you can see it is just a little bit of extra code and then you can set the "gogoproto.jsontag"
extension on all the fields with the desired tag formatting.
I see you are using gogoslick
so you might have to look and add the options from the gogoslick vanity:
https://github.com/gogo/protobuf/blob/master/protoc-gen-gogoslick/main.go
With my example you would use: --gojsoncase_out
to generate your *.pb.go
files.
I, too, would like the generated json
tag to be lower-camel-case so as to be consistent with protojson.Marshal()
.
Leaving it as a per-field option increases boilerplate programming (which can and should be automated) and leaves lots of room for error (eg typos).
Hi, All I am very sorry to disturb.
What is the Question? If we use the following message to generate the golang code, the protobuf json tag and the json tag is different.
As we see, the protobuf json tag name is alignmentId with camel-case. but the json tag name is alignment_id.
What is my expectation? in this case, i wish the json tag name and the protobuf tag name is same like as follow:
Why dose it happen? I checked the code and notice that the json tag name uses the field name directly, see the code here. The snapshot as follow:
I know everyone may have different expectation. so i want to know if it is possible to add an option to control whether the json tag name use camel-case or origin field name?
Why not use the goog tag? The another way to do is as follow:
In this case, we have to set it on every field.