forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
executable file
·40 lines (32 loc) · 864 Bytes
/
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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package balancedsorter
import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/common/selection/balancer"
"github.com/hyperledger/fabric-sdk-go/pkg/common/options"
)
type params struct {
balancer balancer.Balancer
}
func defaultParams() *params {
return ¶ms{
balancer: balancer.RoundRobin(),
}
}
// WithBalancer sets the balancing strategy to use to load balance between the peers
func WithBalancer(value balancer.Balancer) options.Opt {
return func(p options.Params) {
if setter, ok := p.(balancerSetter); ok {
setter.SetBalancer(value)
}
}
}
type balancerSetter interface {
SetBalancer(value balancer.Balancer)
}
func (p *params) SetBalancer(value balancer.Balancer) {
logger.Debugf("Balancer: %#v", value)
p.balancer = value
}