-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.go
47 lines (39 loc) · 884 Bytes
/
example.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
package main
import (
"fmt"
tec "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-temp-err-catcher"
)
var (
ErrTemp = tec.ErrTemporary{fmt.Errorf("ErrTemp")}
ErrSkip = fmt.Errorf("ErrSkip")
ErrOther = fmt.Errorf("ErrOther")
)
func main() {
var normal tec.TempErrCatcher
var skipper tec.TempErrCatcher
skipper.IsTemp = func(e error) bool {
return e == ErrSkip
}
fmt.Println("trying normal (uses Temporary interface)")
tryTec(normal)
fmt.Println("")
fmt.Println("trying skipper (uses our IsTemp function)")
tryTec(skipper)
}
func tryTec(c tec.TempErrCatcher) {
errs := []error{
ErrTemp,
ErrSkip,
ErrOther,
ErrTemp,
ErrSkip,
ErrOther,
}
for _, e := range errs {
if c.IsTemporary(e) {
fmt.Printf("\tIsTemporary: true - skipped %s\n", e)
continue
}
fmt.Printf("\tIsTemporary: false - not skipped %s\n", e)
}
}