...
1 package emperror
2
3 import "sync"
4
5
6
7
8 type TestHandler struct {
9 errors []error
10
11 mu sync.RWMutex
12 }
13
14
15 func NewTestHandler() *TestHandler {
16 return &TestHandler{}
17 }
18
19
20 func (h *TestHandler) Count() int {
21 h.mu.RLock()
22 defer h.mu.RUnlock()
23
24 return len(h.errors)
25 }
26
27
28 func (h *TestHandler) LastError() error {
29 h.mu.RLock()
30 defer h.mu.RUnlock()
31
32 if len(h.errors) < 1 {
33 return nil
34 }
35
36 return h.errors[len(h.errors)-1]
37 }
38
39
40 func (h *TestHandler) Errors() []error {
41 h.mu.RLock()
42 defer h.mu.RUnlock()
43
44 return h.errors
45 }
46
47
48 func (h *TestHandler) Handle(err error) {
49 h.mu.Lock()
50 defer h.mu.Unlock()
51
52 h.errors = append(h.errors, err)
53 }
54
View as plain text