-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
64 lines (55 loc) · 906 Bytes
/
error.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
package aefire
import (
"github.com/labstack/echo/v4"
"log"
)
func NewHttpError(params ...interface{}) *echo.HTTPError {
he := echo.HTTPError{
Code: 500,
}
for _, v := range params {
switch vv := v.(type) {
case int:
he.Code = vv
case string:
he.Message = vv
case echo.HTTPError:
he = vv
case *echo.HTTPError:
he = *vv
case error:
if he.Message == nil {
he.Message = vv.Error()
}
he.Internal = vv
}
}
return &he
}
func PanicIfError(vs ...interface{}) {
for i := len(vs) - 1; i > -1; i-- {
v := vs[i]
if v == nil {
continue
}
switch vv := v.(type) {
case error:
println(vv.Error())
panic(vv)
}
}
}
func LogIfError(vs ...interface{}) bool {
for i := len(vs) - 1; i > -1; i-- {
v := vs[i]
if v == nil {
continue
}
switch vv := v.(type) {
case error:
log.Println(vv.Error())
return true
}
}
return false
}