Skip to content
Permalink
Browse files
调整为1个switch
  • Loading branch information
Changeden committed Oct 12, 2021
1 parent b9d8878 commit 112adfe0422f390e5ed669b551c800975757e65b
Showing 1 changed file with 9 additions and 15 deletions.
@@ -157,21 +157,7 @@ func (e *Encoder) Encode(v interface{}) error {

default:
t := UnpackPtrType(reflect.TypeOf(v))

tKind := t.Kind()

switch tKind {
case reflect.String, reflect.Bool,
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Float32, reflect.Float64: // resolve base type
vVal := reflect.ValueOf(v)
if reflect.Ptr == vVal.Kind() && !vVal.IsNil() {
return e.Encode(vVal.Elem().Interface())
}
}

switch tKind {
switch t.Kind() {
case reflect.Struct:
vv := reflect.ValueOf(v)
vv = UnpackPtr(vv)
@@ -209,6 +195,14 @@ func (e *Encoder) Encode(v interface{}) error {
if err != nil {
return err
}
case reflect.String,
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Float32, reflect.Float64: // resolve base type
vVal := reflect.ValueOf(v)
if reflect.Ptr == vVal.Kind() && !vVal.IsNil() {
return e.Encode(vVal.Elem().Interface())
}
default:
return perrors.Errorf("type not supported! %s", t.Kind().String())
}

0 comments on commit 112adfe

Please sign in to comment.