-
Notifications
You must be signed in to change notification settings - Fork 0
/
operators.go
39 lines (32 loc) · 1.07 KB
/
operators.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
package errors
import "github.com/gofrs/uuid"
// Is return true if err is an error value created by one of the constructor
// of this package and c has the same string representation (value returned by
// the String method) and the same message (value returned by the Message
// method) to the error code, otherwise it returns false.
func Is(err error, c Code) bool {
var derr, ok = err.(derror)
if !ok {
return false
}
return derr.c.String() == c.String() && derr.c.Message() == c.Message()
}
// GetCode returns the Code of the err and true; if err isn't created by any of
// the constructors of this package, false is returned and Code value can be
// ignored.
func GetCode(err error) (Code, bool) {
var derr, ok = err.(derror)
if !ok {
return nil, false
}
return derr.c, true
}
// GetID returns the ID of the err and true; if err isn't created by any of the
// constructors of this package, false is returned and ID value can be ignored.
func GetID(err error) (uuid.UUID, bool) {
var derr, ok = err.(derror)
if !ok {
return uuid.UUID{}, false
}
return derr.id, true
}