2021-07-09 16:56:01 +03:00
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"reflect"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2021-07-12 17:20:01 +03:00
|
|
|
func isEmpty(value interface{}) bool {
|
2021-07-09 16:56:01 +03:00
|
|
|
if value == nil {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reflectValue := reflect.ValueOf(value)
|
|
|
|
|
actualValueInterface := reflectValue.Interface()
|
|
|
|
|
|
2021-07-19 21:04:08 +03:00
|
|
|
// nolint:exhaustive //default branch handles other cases
|
2021-07-09 16:56:01 +03:00
|
|
|
switch reflect.TypeOf(value).Kind() {
|
|
|
|
|
case reflect.String:
|
|
|
|
|
reflectedValue := actualValueInterface.(string)
|
|
|
|
|
return strings.TrimSpace(reflectedValue) == ""
|
2021-07-13 11:12:03 +03:00
|
|
|
case reflect.Slice, reflect.Array, reflect.Map:
|
2021-07-09 16:56:01 +03:00
|
|
|
return reflectValue.Len() == 0
|
|
|
|
|
case reflect.Int32:
|
|
|
|
|
return IsEmpty(string(actualValueInterface.(rune)))
|
|
|
|
|
default:
|
|
|
|
|
if reflectValue.IsZero() {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-12 17:20:01 +03:00
|
|
|
|
|
|
|
|
func IsEmpty(value ...interface{}) bool {
|
|
|
|
|
for _, current := range value {
|
|
|
|
|
if IsNotEmpty(current) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func IsNotEmpty(value interface{}) bool {
|
|
|
|
|
return !isEmpty(value)
|
|
|
|
|
}
|