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

View File

@ -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
}
} }