-
Notifications
You must be signed in to change notification settings - Fork 42
/
route.go
52 lines (41 loc) · 890 Bytes
/
route.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
package gobrake
import (
"context"
)
type routes struct {
filters []routeFilter
stats *routeStats
breakdowns *routeBreakdowns
}
func newRoutes(opt *NotifierOptions) *routes {
return &routes{
stats: newRouteStats(opt),
breakdowns: newRouteBreakdowns(opt),
}
}
// AddFilter adds filter that can change route stat or ignore it by returning nil.
func (rs *routes) AddFilter(fn func(*RouteMetric) *RouteMetric) {
rs.filters = append(rs.filters, fn)
}
func (rs *routes) Flush() {
rs.stats.Flush()
rs.breakdowns.Flush()
}
func (rs *routes) Notify(c context.Context, metric *RouteMetric) error {
metric.finish()
for _, fn := range rs.filters {
metric = fn(metric)
if metric == nil {
return nil
}
}
err := rs.stats.Notify(c, metric)
if err != nil {
return err
}
err = rs.breakdowns.Notify(c, metric)
if err != nil {
return err
}
return nil
}