use reflect in the twmodel.isZero function

This commit is contained in:
Dawid Wysokiński 2021-05-02 15:38:08 +02:00
parent b5464a6da5
commit 117175dd77
1 changed files with 2 additions and 33 deletions

View File

@ -1,40 +1,9 @@
package twmodel
import (
"time"
"reflect"
)
func isZero(v interface{}) bool {
switch c := v.(type) {
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
}
return reflect.ValueOf(v).IsZero()
}