type.go 777 B

123456789101112131415161718192021222324252627282930
  1. package util
  2. import "reflect"
  3. // 判断是否为空字符串
  4. func IsNull(s string) string {
  5. if s == ""{
  6. return "0"
  7. }
  8. return s
  9. }
  10. // 判断 reflect.Value 是否为空
  11. func IsBlank(value reflect.Value) bool {
  12. switch value.Kind() {
  13. case reflect.String:
  14. return value.Len() == 0
  15. case reflect.Bool:
  16. return !value.Bool()
  17. case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
  18. return value.Int() == 0
  19. case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
  20. return value.Uint() == 0
  21. case reflect.Float32, reflect.Float64:
  22. return value.Float() == 0
  23. case reflect.Interface, reflect.Ptr:
  24. return value.IsNil()
  25. }
  26. return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface())
  27. }