-
Notifications
You must be signed in to change notification settings - Fork 10
/
errors.go
49 lines (38 loc) · 820 Bytes
/
errors.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
package errors
import "github.com/go-errors/errors"
type Error interface {
Error() string
Code() uint32
Status() string
}
type err struct {
err string
code uint32
status string
}
func (e *err) Error() string {
return e.err
}
func (e *err) Code() uint32 {
return e.code
}
func (e *err) Status() string {
return e.status
}
func New(code uint32, msg, status string) error {
return &err{code: code, err: msg, status: status}
}
func NewWithError(code uint32, e error, status string) error {
return &err{code: code, err: e.Error(), status: status}
}
func Wrap(e interface{}, skip int) *errors.Error {
return errors.Wrap(e, skip)
}
func Code(u uint32) uint32 {
_, ok := fix[u]
if ok {
panic(New(100001, "code already exists", "code already exists"))
}
return u
}
var fix = map[uint32]uint32{}