Generate gogo stringer instead of proto stringer

Similar to %#v.
This commit is contained in:
Clayton Coleman 2016-07-11 23:19:06 -04:00
parent bea382c124
commit 8c17b48824
No known key found for this signature in database
GPG Key ID: 3D16906B4F1C5CB3
2 changed files with 11 additions and 0 deletions

View File

@ -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]))
}
}

View File

@ -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}