use reflect in the twmodel.isZero function
This commit is contained in:
parent
b5464a6da5
commit
117175dd77
|
@ -1,40 +1,9 @@
|
||||||
package twmodel
|
package twmodel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isZero(v interface{}) bool {
|
func isZero(v interface{}) bool {
|
||||||
switch c := v.(type) {
|
return reflect.ValueOf(v).IsZero()
|
||||||
case string:
|
|
||||||
return c == ""
|
|
||||||
case *string,
|
|
||||||
[]string,
|
|
||||||
[]VersionCode,
|
|
||||||
[]ServerStatus,
|
|
||||||
*int:
|
|
||||||
return c == nil
|
|
||||||
case int:
|
|
||||||
return c == 0
|
|
||||||
case []int:
|
|
||||||
return c == nil
|
|
||||||
case float64:
|
|
||||||
return c == 0
|
|
||||||
case *float64:
|
|
||||||
return c == nil
|
|
||||||
case float32:
|
|
||||||
return c == 0
|
|
||||||
case *float32:
|
|
||||||
return c == nil
|
|
||||||
case bool:
|
|
||||||
return !c
|
|
||||||
case *bool:
|
|
||||||
return c == nil
|
|
||||||
case time.Time:
|
|
||||||
return c.IsZero()
|
|
||||||
case *time.Time:
|
|
||||||
return c == nil
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user