/
opts.go
executable file
·67 lines (54 loc) · 1.48 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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package chconfig
import (
"time"
coptions "github.com/hyperledger/fabric-sdk-go/pkg/common/options"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
)
const (
defaultRefreshInterval = time.Second * 90
)
type params struct {
refreshInterval time.Duration
errHandler fab.ErrorHandler
}
func newDefaultParams() *params {
return ¶ms{
refreshInterval: defaultRefreshInterval,
}
}
// WithRefreshInterval sets the interval in which the
// channel config cache is refreshed
func WithRefreshInterval(value time.Duration) coptions.Opt {
return func(p coptions.Params) {
if setter, ok := p.(refreshIntervalSetter); ok {
setter.SetChConfigRefreshInterval(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 {
SetChConfigRefreshInterval(value time.Duration)
}
type errHandlerSetter interface {
SetErrorHandler(value fab.ErrorHandler)
}
func (o *params) SetChConfigRefreshInterval(value time.Duration) {
logger.Debugf("RefreshInterval: %s", value)
o.refreshInterval = value
}
func (o *params) SetErrorHandler(value fab.ErrorHandler) {
logger.Debugf("ErrorHandler: %+v", value)
o.errHandler = value
}