diff --git a/gogoproto/helper.go b/gogoproto/helper.go index 390d4e4be6..92f9d1c664 100644 --- a/gogoproto/helper.go +++ b/gogoproto/helper.go @@ -28,8 +28,10 @@ package gogoproto -import google_protobuf "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" -import proto "github.com/gogo/protobuf/proto" +import ( + proto "github.com/gogo/protobuf/proto" + google_protobuf "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" +) func IsEmbed(field *google_protobuf.FieldDescriptorProto) bool { return proto.GetBoolExtension(field.Options, E_Embed, false) @@ -109,34 +111,22 @@ func NeedsNilCheck(proto3 bool, field *google_protobuf.FieldDescriptorProto) boo func IsCustomType(field *google_protobuf.FieldDescriptorProto) bool { typ := GetCustomType(field) - if len(typ) > 0 { - return true - } - return false + return len(typ) > 0 } func IsCastType(field *google_protobuf.FieldDescriptorProto) bool { typ := GetCastType(field) - if len(typ) > 0 { - return true - } - return false + return len(typ) > 0 } func IsCastKey(field *google_protobuf.FieldDescriptorProto) bool { typ := GetCastKey(field) - if len(typ) > 0 { - return true - } - return false + return len(typ) > 0 } func IsCastValue(field *google_protobuf.FieldDescriptorProto) bool { typ := GetCastValue(field) - if len(typ) > 0 { - return true - } - return false + return len(typ) > 0 } func HasEnumDecl(file *google_protobuf.FileDescriptorProto, enum *google_protobuf.EnumDescriptorProto) bool { @@ -201,26 +191,17 @@ func GetCastValue(field *google_protobuf.FieldDescriptorProto) string { func IsCustomName(field *google_protobuf.FieldDescriptorProto) bool { name := GetCustomName(field) - if len(name) > 0 { - return true - } - return false + return len(name) > 0 } func IsEnumCustomName(field *google_protobuf.EnumDescriptorProto) bool { name := GetEnumCustomName(field) - if len(name) > 0 { - return true - } - return false + return len(name) > 0 } func IsEnumValueCustomName(field *google_protobuf.EnumValueDescriptorProto) bool { name := GetEnumValueCustomName(field) - if len(name) > 0 { - return true - } - return false + return len(name) > 0 } func GetCustomName(field *google_protobuf.FieldDescriptorProto) string { diff --git a/protoc-gen-gogo/generator/helper.go b/protoc-gen-gogo/generator/helper.go index 7091e281cb..c42f16f08e 100644 --- a/protoc-gen-gogo/generator/helper.go +++ b/protoc-gen-gogo/generator/helper.go @@ -373,7 +373,7 @@ func (g *Generator) generatePlugin(file *FileDescriptor, p Plugin) { g.Write(rem.Bytes()) // Reformat generated code. - contents := string(g.Buffer.Bytes()) + contents := g.Buffer.String() fset := token.NewFileSet() ast, err := parser.ParseFile(fset, "", g, parser.ParseComments) if err != nil { diff --git a/test/deterministic/deterministic_test.go b/test/deterministic/deterministic_test.go index e6edc530ec..e1c360230f 100644 --- a/test/deterministic/deterministic_test.go +++ b/test/deterministic/deterministic_test.go @@ -30,8 +30,9 @@ package deterministic import ( "bytes" - "github.com/gogo/protobuf/proto" "testing" + + "github.com/gogo/protobuf/proto" ) func getTestMap() map[string]string { @@ -75,7 +76,7 @@ func TestOrderedMap(t *testing.T) { if err != nil { t.Fatal(err) } - if bytes.Compare(data1, data2) != 0 { + if !bytes.Equal(data1, data2) { t.Fatal("byte arrays are not the same\n", data1, "\n", data2) } } @@ -121,7 +122,7 @@ func TestMapNoMarshaler(t *testing.T) { } data2 := b2.Bytes() - if bytes.Compare(data1, data2) != 0 { + if !bytes.Equal(data1, data2) { t.Fatal("byte arrays are not the same:\n", data1, "\n", data2) } } @@ -149,7 +150,7 @@ func TestOrderedNestedMap(t *testing.T) { if err != nil { t.Fatal(err) } - if bytes.Compare(data1, data2) != 0 { + if !bytes.Equal(data1, data2) { t.Fatal("byte arrays are not the same\n", data1, "\n", data2) } } @@ -189,7 +190,7 @@ func TestOrderedNestedStructMap(t *testing.T) { if err != nil { t.Fatal(err) } - if bytes.Compare(data1, data2) != 0 { + if !bytes.Equal(data1, data2) { t.Fatal("byte arrays are not the same\n", data1, "\n", data2) } }