blob: a8711fb9a732a122d9e44b57700a5c5b11d339ec (
plain)
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
|
package errors_test
import (
"encoding/json"
"errors"
"fmt"
"log"
liberrors "github.com/shuLhan/share/lib/errors"
)
func ExampleE_Is() {
var (
errFileNotFound = &liberrors.E{
Code: 400,
Name: `ERR_NOT_FOUND`,
Message: `file not found`,
}
errResNotFound = &liberrors.E{
Code: 404,
Name: `ERR_NOT_FOUND`,
Message: `resource not found`,
}
rawJson = `{"code":400,"name":"ERR_NOT_FOUND","message":"file not found"}`
e *liberrors.E
err error
)
err = json.Unmarshal([]byte(rawJson), &e)
if err != nil {
log.Fatal(err)
}
var gotErr error = e
fmt.Println(errors.Is(gotErr, errFileNotFound))
fmt.Println(errors.Is(gotErr, errResNotFound))
// Output:
// true
// false
}
|