forked from johnbellone/grpc-middleware-sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
79 lines (60 loc) · 1.42 KB
/
config.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
package grpc_sentry
import "time"
type Option interface {
Apply(*options)
}
// newConfig returns a config configured with all the passed Options.
func newConfig(opts []Option) *options {
optsCopy := *defaultOptions
c := &optsCopy
for _, o := range opts {
o.Apply(c)
}
return c
}
type repanicOption struct {
Repanic bool
}
func (r *repanicOption) Apply(o *options) {
o.Repanic = r.Repanic
}
func WithRepanicOption(b bool) Option {
return &repanicOption{Repanic: b}
}
type waitForDeliveryOption struct {
WaitForDelivery bool
}
func (w *waitForDeliveryOption) Apply(o *options) {
o.WaitForDelivery = w.WaitForDelivery
}
func WithWaitForDelivery(b bool) Option {
return &waitForDeliveryOption{WaitForDelivery: b}
}
type timeoutOption struct {
Timeout time.Duration
}
func (t *timeoutOption) Apply(o *options) {
o.Timeout = t.Timeout
}
func WithTimeout(t time.Duration) Option {
return &timeoutOption{Timeout: t}
}
type reporter func(error) bool
type reportOnOption struct {
ReportOn reporter
}
func (r *reportOnOption) Apply(o *options) {
o.ReportOn = r.ReportOn
}
func WithReportOn(r reporter) Option {
return &reportOnOption{ReportOn: r}
}
type operationNameOverride struct {
OperationNameOverride string
}
func (r *operationNameOverride) Apply(o *options) {
o.OperationNameOverride = r.OperationNameOverride
}
func WithOperationNameOverride(s string) Option {
return &operationNameOverride{OperationNameOverride: s}
}