-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (52 loc) · 1 KB
/
main.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
package describe
import (
"errors"
"fmt"
"os"
)
// IsErr is error or not
func IsErr(e error) bool {
return e != nil
}
// CheckErr panic if it is error
func CheckErr(e error) {
if IsErr(e) {
panic(e)
}
}
// NewErr return new error
func NewErr(msg ...interface{}) error {
ss := StringSlice(nil)
for _, s := range msg {
ss.Push(fmt.Sprint(s))
}
return errors.New(ss.Join(" ").Get())
}
// RecoverErr run function when recover an error, it will panic again if it is not error
func RecoverErr(f func(error)) {
if r := recover(); r != nil {
e, is := r.(error)
if !is {
panic(r)
}
if f != nil {
f(e)
}
}
}
// GetENV get env or use default
func GetENV(name string, defaultVal string) string {
v := os.Getenv(name)
if v == "" {
return defaultVal
}
return v
}
// Found check Slice.Find() return valid element or not
func Found(elm interface{}) bool {
return elm != nil
}
// NotFound check Slice.Find() return valid element or not
func NotFound(elm interface{}) bool {
return elm == nil
}