-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
100 lines (83 loc) · 2.54 KB
/
opts.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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package fabricselection
import (
"time"
"github.com/xlongit/fabric-sdk-go-gm/pkg/common/errors/retry"
coptions "github.com/xlongit/fabric-sdk-go-gm/pkg/common/options"
"github.com/xlongit/fabric-sdk-go-gm/pkg/common/providers/fab"
)
type params struct {
refreshInterval time.Duration
responseTimeout time.Duration
retryOpts retry.Opts
errHandler fab.ErrorHandler
}
// WithRefreshInterval sets the interval in which the
// peer cache is refreshed
func WithRefreshInterval(value time.Duration) coptions.Opt {
return func(p coptions.Params) {
logger.Debug("Checking refreshIntervalSetter")
if setter, ok := p.(refreshIntervalSetter); ok {
setter.SetSelectionRefreshInterval(value)
}
}
}
// WithResponseTimeout sets the Discover service response timeout
func WithResponseTimeout(value time.Duration) coptions.Opt {
return func(p coptions.Params) {
logger.Debug("Checking responseTimeoutSetter")
if setter, ok := p.(responseTimeoutSetter); ok {
setter.SetSelectionResponseTimeout(value)
}
}
}
// WithRetryOpts sets retry options for retries on transient errors
// from the Discovery Server
func WithRetryOpts(value retry.Opts) coptions.Opt {
return func(p coptions.Params) {
logger.Debug("Checking retryOptsSetter")
if setter, ok := p.(retryOptsSetter); ok {
setter.SetSelectionRetryOpts(value)
}
}
}
// WithErrorHandler sets the error handler
func WithErrorHandler(value fab.ErrorHandler) coptions.Opt {
return func(p coptions.Params) {
logger.Debug("Checking errHandlerSetter")
if setter, ok := p.(errHandlerSetter); ok {
setter.SetErrorHandler(value)
}
}
}
type refreshIntervalSetter interface {
SetSelectionRefreshInterval(value time.Duration)
}
type responseTimeoutSetter interface {
SetSelectionResponseTimeout(value time.Duration)
}
type retryOptsSetter interface {
SetSelectionRetryOpts(value retry.Opts)
}
type errHandlerSetter interface {
SetErrorHandler(value fab.ErrorHandler)
}
func (o *params) SetSelectionRefreshInterval(value time.Duration) {
logger.Debugf("RefreshInterval: %s", value)
o.refreshInterval = value
}
func (o *params) SetSelectionResponseTimeout(value time.Duration) {
logger.Debugf("ResponseTimeout: %s", value)
o.responseTimeout = value
}
func (o *params) SetSelectionRetryOpts(value retry.Opts) {
logger.Debugf("RetryOpts: %#v", value)
o.retryOpts = value
}
func (o *params) SetErrorHandler(value fab.ErrorHandler) {
logger.Debugf("ErrorHandler: %+v", value)
o.errHandler = value
}