-
Notifications
You must be signed in to change notification settings - Fork 12
/
errors.go
103 lines (86 loc) · 1.81 KB
/
errors.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package gohalt
import (
"fmt"
"time"
)
type strbool bool
func (b strbool) String() string {
return fmt.Sprintf("%t", bool(b))
}
type strpair struct {
current uint64
threshold uint64
}
func (p strpair) String() string {
return fmt.Sprintf("%d out of %d", p.current, p.threshold)
}
type strpercent float64
func (p strpercent) String() string {
return fmt.Sprintf("%.4f%%", float64(p)*100)
}
type strdurations struct {
current time.Duration
threshold time.Duration
}
func (d strdurations) String() string {
return fmt.Sprintf("%s out of %s", d.current, d.threshold)
}
type strtimes struct {
current time.Time
threshold time.Time
}
func (d strtimes) String() string {
return fmt.Sprintf(
"%s out of %s",
d.current.Format(time.RFC3339Nano),
d.threshold.Format(time.RFC3339Nano),
)
}
type strstats struct {
current Stats
threshold Stats
}
func (s strstats) String() string {
return fmt.Sprintf(
`
%d out of %d bytes
%d out of %d bytes
%d out of %d ns
%.4f out of %.4f %%
`,
s.current.MEMAlloc,
s.threshold.MEMAlloc,
s.current.MEMSystem,
s.threshold.MEMSystem,
s.current.CPUPause,
s.threshold.CPUPause,
s.current.CPUUsage*100,
s.threshold.CPUUsage*100,
)
}
// ErrorThreshold defines error type
// that occurs if throttler reaches specified threshold.
type ErrorThreshold struct {
Throttler string
Threshold fmt.Stringer
}
func (err ErrorThreshold) Error() string {
return fmt.Sprintf(
"throttler %q has reached its threshold: %s",
err.Throttler,
err.Threshold,
)
}
// ErrorInternal defines error type
// that occurs if throttler internal error happens.
type ErrorInternal struct {
Throttler string
Message string
}
func (err ErrorInternal) Error() string {
return fmt.Sprintf(
"throttler %q internal error happened: %s",
err.Throttler,
err.Message,
)
}