...
1
2
3
4 package grpc_recovery
5
6 import "context"
7
8 var (
9 defaultOptions = &options{
10 recoveryHandlerFunc: nil,
11 }
12 )
13
14 type options struct {
15 recoveryHandlerFunc RecoveryHandlerFuncContext
16 }
17
18 func evaluateOptions(opts []Option) *options {
19 optCopy := &options{}
20 *optCopy = *defaultOptions
21 for _, o := range opts {
22 o(optCopy)
23 }
24 return optCopy
25 }
26
27 type Option func(*options)
28
29
30 func WithRecoveryHandler(f RecoveryHandlerFunc) Option {
31 return func(o *options) {
32 o.recoveryHandlerFunc = RecoveryHandlerFuncContext(func(ctx context.Context, p interface{}) error {
33 return f(p)
34 })
35 }
36 }
37
38
39 func WithRecoveryHandlerContext(f RecoveryHandlerFuncContext) Option {
40 return func(o *options) {
41 o.recoveryHandlerFunc = f
42 }
43 }
44
View as plain text