forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zero.go
65 lines (62 loc) · 1.17 KB
/
zero.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package reflex
import (
"encoding/json"
"net"
)
// Zeroer can be implemented by custom types
// to report whether its current value is zero.
// Standard Time also implements that.
type Zeroer interface {
IsZero() bool
}
// IsZero reports whether "v" is zero value or no.
// The given "v" value can complete the Zeroer interface
// which can be used to customize the behavior for each type of "v".
func IsZero(v interface{}) bool {
switch t := v.(type) {
case Zeroer: // completes the time.Time as well.
return t.IsZero()
case string:
return t == ""
case int:
return t == 0
case int8:
return t == 0
case int16:
return t == 0
case int32:
return t == 0
case int64:
return t == 0
case uint:
return t == 0
case uint8:
return t == 0
case uint16:
return t == 0
case uint32:
return t == 0
case uint64:
return t == 0
case float32:
return t == 0
case float64:
return t == 0
case bool:
return !t
case []int:
return len(t) == 0
case []string:
return len(t) == 0
case [][]int:
return len(t) == 0
case [][]string:
return len(t) == 0
case json.Number:
return t.String() == ""
case net.IP:
return len(t) == 0
default:
return false
}
}