1package main
2
3import (
4	"fmt"
5
6	tec "github.com/jbenet/go-temp-err-catcher"
7)
8
9var (
10	ErrTemp  = tec.ErrTemporary{fmt.Errorf("ErrTemp")}
11	ErrSkip  = fmt.Errorf("ErrSkip")
12	ErrOther = fmt.Errorf("ErrOther")
13)
14
15func main() {
16	var normal tec.TempErrCatcher
17	var skipper tec.TempErrCatcher
18	skipper.IsTemp = func(e error) bool {
19		return e == ErrSkip
20	}
21
22	fmt.Println("trying normal (uses Temporary interface)")
23	tryTec(normal)
24	fmt.Println("")
25	fmt.Println("trying skipper (uses our IsTemp function)")
26	tryTec(skipper)
27}
28
29func tryTec(c tec.TempErrCatcher) {
30	errs := []error{
31		ErrTemp,
32		ErrSkip,
33		ErrOther,
34		ErrTemp,
35		ErrSkip,
36		ErrOther,
37	}
38
39	for _, e := range errs {
40		if c.IsTemporary(e) {
41			fmt.Printf("\tIsTemporary: true  - skipped     %s\n", e)
42			continue
43		}
44
45		fmt.Printf("\tIsTemporary: false - not skipped %s\n", e)
46	}
47}
48