Skip to content

Commit fe8430d

Browse files
committed
cmd/protoc-gen-go: remove json struct tags from unexported fields
This commit does not change behavior because the encoding/json package ignores unexported fields. To encode a Protobuf message into JSON, users should reach for protobuf/encoding/protojson. With this change, the generated code (.pb.go files) passes go vet. I also made the integration test run go vet so that we do not regress. For golang/protobuf#1657 Fixes golang/protobuf#1658 Change-Id: I0a677d09e4517b2649bfcfe76a49194c7ccbb823 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/641036 Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Chressie Himpel <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 84f7738 commit fe8430d

File tree

23 files changed

+1086
-1073
lines changed

23 files changed

+1086
-1073
lines changed

cmd/protoc-gen-go/internal_gengo/opaque.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ func opaqueGenMessageField(g *protogen.GeneratedFile, f *fileInfo, message *mess
9393
}
9494
tags := structTags{
9595
{"protobuf", protobufTagValue},
96-
{"json", jsonTagValue},
96+
}
97+
if !message.isOpaque() {
98+
tags = append(tags, structTags{{"json", jsonTagValue}}...)
9799
}
98100
if field.Desc.IsMap() {
99101
keyTagValue := fieldProtobufTagValue(field.Message.Fields[0])

cmd/protoc-gen-go/testdata/nameclash/test_name_clash_hybrid/test_name_clash_hybrid_protoopaque.pb.go

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)