Skip to content

Commit

Permalink
golint: return
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnake0 committed Oct 8, 2020
1 parent c2fac56 commit 67c4b29
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 80 deletions.
5 changes: 2 additions & 3 deletions encoder_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ func (cache encoderCache) preferPtrEncoder(typ reflect.Type) ValEncoder {
ptrEncoder := cache[rtypeOfType(ptrType)]
if pe, ok := ptrEncoder.(*pointerEncoder); ok {
return pe.encoder
} else {
// the element has a special pointer encoder
return &directEncoder{ptrEncoder}
}
// the element has a special pointer encoder
return &directEncoder{ptrEncoder}
}

type EncoderConfig struct {
Expand Down
21 changes: 10 additions & 11 deletions iterator_int16.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,18 @@ func (it *Iterator) readInt16(c byte) (int16, error) {
}
}
return -int16(v), nil
} else {
v, err := it.readUint16(c)
if err != nil {
return 0, err
}
if v > math.MaxInt16 {
return 0, IntOverflowError{
typ: "int16",
value: strconv.FormatUint(uint64(v), 10),
}
}
v, err := it.readUint16(c)
if err != nil {
return 0, err
}
if v > math.MaxInt16 {
return 0, IntOverflowError{
typ: "int16",
value: strconv.FormatUint(uint64(v), 10),
}
return int16(v), nil
}
return int16(v), nil
}

func (it *Iterator) ReadInt16() (int16, error) {
Expand Down
21 changes: 10 additions & 11 deletions iterator_int32.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,18 @@ func (it *Iterator) readInt32(c byte) (int32, error) {
}
}
return -int32(v), nil
} else {
v, err := it.readUint32(c)
if err != nil {
return 0, err
}
if v > math.MaxInt32 {
return 0, IntOverflowError{
typ: "int32",
value: strconv.FormatUint(uint64(v), 10),
}
}
v, err := it.readUint32(c)
if err != nil {
return 0, err
}
if v > math.MaxInt32 {
return 0, IntOverflowError{
typ: "int32",
value: strconv.FormatUint(uint64(v), 10),
}
return int32(v), nil
}
return int32(v), nil
}

func (it *Iterator) ReadInt32() (int32, error) {
Expand Down
21 changes: 10 additions & 11 deletions iterator_int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,18 @@ func (it *Iterator) readInt64(c byte) (int64, error) {
}
}
return -int64(v), nil
} else {
v, err := it.readUint64(c)
if err != nil {
return 0, err
}
if v > math.MaxInt64 {
return 0, IntOverflowError{
typ: "int64",
value: strconv.FormatUint(uint64(v), 10),
}
}
v, err := it.readUint64(c)
if err != nil {
return 0, err
}
if v > math.MaxInt64 {
return 0, IntOverflowError{
typ: "int64",
value: strconv.FormatUint(uint64(v), 10),
}
return int64(v), nil
}
return int64(v), nil
}

func (it *Iterator) ReadInt64() (int64, error) {
Expand Down
21 changes: 10 additions & 11 deletions iterator_int8.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,18 @@ func (it *Iterator) readInt8(c byte) (int8, error) {
}
}
return -int8(v), nil
} else {
v, err := it.readUint8(c)
if err != nil {
return 0, err
}
if v > math.MaxInt8 {
return 0, IntOverflowError{
typ: "int8",
value: strconv.FormatUint(uint64(v), 10),
}
}
v, err := it.readUint8(c)
if err != nil {
return 0, err
}
if v > math.MaxInt8 {
return 0, IntOverflowError{
typ: "int8",
value: strconv.FormatUint(uint64(v), 10),
}
return int8(v), nil
}
return int8(v), nil
}

func (it *Iterator) ReadInt8() (int8, error) {
Expand Down
3 changes: 1 addition & 2 deletions iterator_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ func init() {
if it.useNumber {
s, err := it.readNumberAsString(c)
return json.Number(s), err
} else {
return it.readFloat64(c)
}
return it.readFloat64(c)
}
}
errFunc := func(it *Iterator, c byte) (interface{}, error) {
Expand Down
3 changes: 1 addition & 2 deletions iterator_str.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ Retry:
goto Retry
}
return appendRune(b, combined), nil
} else {
return appendRune(b, r), nil
}
return appendRune(b, r), nil
}

// internal, call only after a '"' is consumed
Expand Down
3 changes: 1 addition & 2 deletions streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ func (s *Streamer) False() *Streamer {
func (s *Streamer) Bool(b bool) *Streamer {
if b {
return s.True()
} else {
return s.False()
}
return s.False()
}

func (s *Streamer) ObjectStart() *Streamer {
Expand Down
12 changes: 4 additions & 8 deletions streamer_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ func appendInt8(b []byte, v int8) []byte {
if v < 0 {
b = append(b, '-')
return appendUint8(b, uint8(-v))
} else {
return appendUint8(b, uint8(v))
}
return appendUint8(b, uint8(v))
}

func (s *Streamer) quotedInt8(v int8) *Streamer {
Expand Down Expand Up @@ -102,9 +101,8 @@ func appendInt16(b []byte, v int16) []byte {
if v < 0 {
b = append(b, '-')
return appendUint16(b, uint16(-v))
} else {
return appendUint16(b, uint16(v))
}
return appendUint16(b, uint16(v))
}

func (s *Streamer) quotedInt16(v int16) *Streamer {
Expand Down Expand Up @@ -176,9 +174,8 @@ func appendInt32(b []byte, v int32) []byte {
if v < 0 {
b = append(b, '-')
return appendUint32(b, uint32(-v))
} else {
return appendUint32(b, uint32(v))
}
return appendUint32(b, uint32(v))
}

func (s *Streamer) quotedInt32(v int32) *Streamer {
Expand Down Expand Up @@ -271,9 +268,8 @@ func appendInt64(b []byte, v int64) []byte {
if v < 0 {
b = append(b, '-')
return appendUint64(b, uint64(-v))
} else {
return appendUint64(b, uint64(v))
}
return appendUint64(b, uint64(v))
}

func (s *Streamer) quotedInt64(v int64) *Streamer {
Expand Down
15 changes: 7 additions & 8 deletions val_decoder_native_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ func copyValue(t *testing.T, in interface{}) (out interface{}) {
if ptrValue.IsNil() {
newV := reflect.NewAt(typ.Elem(), nil)
return newV.Interface()
} else {
elem := ptrValue.Elem()
copied := copyValue(t, elem.Interface())
newV := reflect.New(elem.Type())
if copied != nil {
newV.Elem().Set(reflect.ValueOf(copied))
}
return newV.Interface()
}
elem := ptrValue.Elem()
copied := copyValue(t, elem.Interface())
newV := reflect.New(elem.Type())
if copied != nil {
newV.Elem().Set(reflect.ValueOf(copied))
}
return newV.Interface()
case reflect.Struct:
oldV := reflect.ValueOf(in)
newV := reflect.New(typ).Elem()
Expand Down
13 changes: 6 additions & 7 deletions val_decoder_native_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ func (df *decoderFields) find(key, buf []byte, caseSensitive bool) (*decoderFiel
return &df.list[i], upper
}
return nil, upper
} else {
for i := range df.list {
ff := &df.list[i]
if ff.equalFold(ff.nameBytes, key) {
return ff, buf
}
}
for i := range df.list {
ff := &df.list[i]
if ff.equalFold(ff.nameBytes, key) {
return ff, buf
}
return nil, buf
}
return nil, buf
}

type structDecoder struct {
Expand Down
3 changes: 1 addition & 2 deletions val_decoder_skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ func (*emptyObjectDecoder) Decode(ptr unsafe.Pointer, it *Iterator, _ *DecOpts)
return UnexpectedByteError{got: c, exp: '}'}
}
return nil
} else {
return skipFunctions[c](it, c)
}
return skipFunctions[c](it, c)
default:
return UnexpectedByteError{got: c, exp: '{', exp2: 'n'}
}
Expand Down
3 changes: 1 addition & 2 deletions val_encoder_json_marshaler_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ type testBoolJsonMarshaler bool
func (b testBoolJsonMarshaler) MarshalJSON() ([]byte, error) {
if b {
return []byte("true"), nil
} else {
return []byte("false"), nil
}
return []byte("false"), nil
}

// array
Expand Down

0 comments on commit 67c4b29

Please sign in to comment.