Skip to content

Commit

Permalink
reduce var (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong authored Mar 11, 2024
1 parent dc701cd commit cff5d43
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions internal/convert/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ func (c Converter) convertSlice(name string, fromVal, toVal reflect.Value) error

return errors.Join(errs...)
case fromVal.Kind() == reflect.String && toVal.Type().Elem().Kind() == reflect.Uint8:
s := fromVal.String()
toVal.SetBytes(internal.String2ByteSlice(s))
toVal.SetBytes(internal.String2ByteSlice(fromVal.String()))
case fromVal.Kind() == reflect.Map:
// Empty maps turn into empty arrays
if fromVal.Len() == 0 {
Expand Down Expand Up @@ -459,8 +458,7 @@ func (c Converter) convertString(name string, fromVal, toVal reflect.Value) erro
reflect.Copy(reflect.ValueOf(bytes), fromVal)
toVal.SetString(internal.ByteSlice2String(bytes))
case fromVal.Kind() == reflect.Slice && fromVal.Type().Elem().Kind() == reflect.Uint8:
bytes := fromVal.Bytes()
toVal.SetString(internal.ByteSlice2String(bytes))
toVal.SetString(internal.ByteSlice2String(fromVal.Bytes()))
default:
return fmt.Errorf( //nolint:goerr113
"'%s' expected type '%s', got unconvertible type '%s', value: '%v'",
Expand Down

0 comments on commit cff5d43

Please sign in to comment.