From 68bfba29b9cd89a076675e1f5409da4b853234b6 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Mon, 11 Jul 2016 22:12:56 -0400 Subject: [PATCH] Allow proto tag to define field name When we introduce a new field for backwards compatibility, we may want to specify a different protobuf field name (one that matches JSON) than the automatic transformation applied to the struct field. This allows an API field to define the name of its protobuf tag. --- cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go b/cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go index a41cf3c8c30..14d037a0070 100644 --- a/cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go +++ b/cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go @@ -589,6 +589,8 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types. return fmt.Errorf("member %q of %q malformed 'protobuf' tag, tag %d should be key=value, got %q\n", m.Name, t.Name, i+4, extra) } switch parts[0] { + case "name": + protoExtra[parts[0]] = parts[1] case "casttype", "castkey", "castvalue": parts[0] = fmt.Sprintf("(gogoproto.%s)", parts[0]) protoExtra[parts[0]] = parts[1]