should use bytes.Equal(a.([]byte), b.([]byte)) instead
57
58 switch a.(type) {
59 case []byte:
60 return bytes.Compare(a.([]byte), b.([]byte)) == 0, nil61 case string:
62 return strings.Compare(a.(string), b.(string)) == 0, nil
63 default:
Description
Prefer using bytes.Equal
for checking equality of two byte
slices instead of
bytes.Compare
.
Instead of using bytes.Compare
to check whether two byte
slices are equal,
the shorthand bytes.Equal
, created explicitly for checking equality, could
be used.
Bad practice
if bytes.Compare(x, y) == 0 {}
Recommended
if bytes.Equal(x, y) {}