diff --git a/client/http/codec.go b/client/http/codec.go index 0512c5adce9f..b5ea888b59c2 100644 --- a/client/http/codec.go +++ b/client/http/codec.go @@ -64,11 +64,11 @@ func encodeBytes(data []byte) []byte { return result } -func decodeBytes(b []byte) ([]byte, []byte, error) { +func decodeBytes(b []byte) ([]byte, error) { buf := make([]byte, 0, len(b)) for { if len(b) < encGroupSize+1 { - return nil, nil, errors.New("insufficient bytes to decode value") + return nil, errors.New("insufficient bytes to decode value") } groupBytes := b[:encGroupSize+1] @@ -78,7 +78,7 @@ func decodeBytes(b []byte) ([]byte, []byte, error) { padCount := encMarker - marker if padCount > encGroupSize { - return nil, nil, errors.Errorf("invalid marker byte, group bytes %q", groupBytes) + return nil, errors.Errorf("invalid marker byte, group bytes %q", groupBytes) } realGroupSize := encGroupSize - padCount @@ -89,11 +89,11 @@ func decodeBytes(b []byte) ([]byte, []byte, error) { // Check validity of padding bytes. for _, v := range group[realGroupSize:] { if v != encPad { - return nil, nil, errors.Errorf("invalid padding byte, group bytes %q", groupBytes) + return nil, errors.Errorf("invalid padding byte, group bytes %q", groupBytes) } } break } } - return b, buf, nil + return buf, nil } diff --git a/client/http/codec_test.go b/client/http/codec_test.go index cf3f42430fee..fa8d413a0d12 100644 --- a/client/http/codec_test.go +++ b/client/http/codec_test.go @@ -39,7 +39,7 @@ func TestBytesCodec(t *testing.T) { b := encodeBytes(input.enc) require.Equal(t, input.dec, b) - _, d, err := decodeBytes(b) + d, err := decodeBytes(b) require.NoError(t, err) require.Equal(t, input.enc, d) } @@ -58,7 +58,7 @@ func TestBytesCodec(t *testing.T) { } for _, input := range errInputs { - _, _, err := decodeBytes(input) + _, err := decodeBytes(input) require.Error(t, err) } } diff --git a/client/http/types.go b/client/http/types.go index fb95927accf8..1b706f0223c7 100644 --- a/client/http/types.go +++ b/client/http/types.go @@ -327,12 +327,12 @@ func (r *Rule) UnmarshalJSON(bytes []byte) error { return err } - _, r.StartKey, err = decodeBytes(startKey) + r.StartKey, err = decodeBytes(startKey) if err != nil { return err } - _, r.EndKey, err = decodeBytes(endKey) + r.EndKey, err = decodeBytes(endKey) return err } @@ -388,12 +388,12 @@ func (r *RuleOp) UnmarshalJSON(bytes []byte) error { return err } - _, r.StartKey, err = decodeBytes(startKey) + r.StartKey, err = decodeBytes(startKey) if err != nil { return err } - _, r.EndKey, err = decodeBytes(endKey) + r.EndKey, err = decodeBytes(endKey) return err }