-
Notifications
You must be signed in to change notification settings - Fork 1
/
gerr.go
61 lines (50 loc) · 1.3 KB
/
gerr.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
package ctx
import "fmt"
type GErrors []*GError
type GError struct {
Code uint `json:"code,omitempty"`
Err error `json:"-"`
Domain string `json:"domain,omitempty"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
Location string `json:"location,omitempty"`
LocationType string `json:"locationType,omitempty"`
ExtendedHelp string `json:"extendedHelp,omitempty"`
SendReport string `json:"sendReport,omitempty"`
}
func (g *GError) Error() string {
if g.Err != nil {
return fmt.Sprintf("%s:%s %s, Err:%s", g.Domain, g.Reason, g.Message, g.Err.Error())
}
return fmt.Sprintf("%s:%s %s", g.Domain, g.Reason, g.Message)
}
func (g *GError) AppendDomain(domain string) error {
g.Domain = domain + "." + g.Domain
return g
}
func (c *GErrors) Append(gErr *GError) *GErrors {
*c = append(*c, gErr)
return c
}
func (c *GErrors) AppendDomain(domain string) *GErrors {
for idx := range *c {
(*c)[idx].Domain = domain + "." + (*c)[idx].Domain
}
return c
}
func (c *GErrors) Empty() bool {
return len(*c) == 0
}
func (c *GErrors) Code() uint {
if c.Empty() {
return 0
}
return (*c)[0].Code
}
func (c *GErrors) Message() string {
if c.Empty() {
return ""
}
return (*c)[0].Message
}
func NewGErrors() *GErrors { return &GErrors{} }