From 8c17b48824c56f5042fe23d60001683427ffdce6 Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Mon, 11 Jul 2016 23:19:06 -0400 Subject: [PATCH] Generate gogo stringer instead of proto stringer Similar to %#v. --- cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go | 5 +++++ pkg/api/unversioned/time.go | 6 ++++++ 2 files changed, 11 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..22e2d8823b4 100644 --- a/cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go +++ b/cmd/libs/go2idl/go-to-protobuf/protobuf/generator.go @@ -53,6 +53,8 @@ func (g *genProtoIDL) PackageVars(c *generator.Context) []string { return []string{ "option (gogoproto.marshaler_all) = true;", "option (gogoproto.sizer_all) = true;", + "option (gogoproto.goproto_stringer_all) = false;", + "option (gogoproto.stringer_all) = true;", "option (gogoproto.unmarshaler_all) = true;", "option (gogoproto.goproto_unrecognized_all) = false;", "option (gogoproto.goproto_enum_prefix_all) = false;", @@ -316,6 +318,9 @@ func (b bodyGen) doStruct(sw *generator.SnippetWriter) error { } default: if !b.omitGogo || !strings.HasPrefix(key, "(gogoproto.") { + if key == "(gogoproto.goproto_stringer)" && v[0] == "false" { + options = append(options, "(gogoproto.stringer) = false") + } options = append(options, fmt.Sprintf("%s = %s", key, v[0])) } } diff --git a/pkg/api/unversioned/time.go b/pkg/api/unversioned/time.go index 73b00f2e7c2..7e6281a2052 100644 --- a/pkg/api/unversioned/time.go +++ b/pkg/api/unversioned/time.go @@ -29,6 +29,7 @@ import ( // // +protobuf.options.marshal=false // +protobuf.as=Timestamp +// +protobuf.options.(gogoproto.goproto_stringer)=false type Time struct { time.Time `protobuf:"-"` } @@ -40,6 +41,11 @@ func (t Time) DeepCopy() Time { return t } +// String returns the representation of the time. +func (t Time) String() string { + return t.Time.String() +} + // NewTime returns a wrapped instance of the provided time func NewTime(time time.Time) Time { return Time{time}