forked from sonm-io/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
92 lines (78 loc) · 1.8 KB
/
options.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
package hub
import (
"crypto/ecdsa"
"github.com/ethereum/go-ethereum/common"
"github.com/sonm-io/core/blockchain"
pb "github.com/sonm-io/core/proto"
"github.com/sonm-io/core/util"
"golang.org/x/net/context"
"google.golang.org/grpc/credentials"
)
// options for building hub instance
type options struct {
version string
ctx context.Context
ethKey *ecdsa.PrivateKey
ethAddr common.Address
bcr blockchain.Blockchainer
market pb.MarketClient
locator pb.LocatorClient
creds credentials.TransportCredentials
rot util.HitlessCertRotator
cluster Cluster
clusterEvents <-chan ClusterEvent
}
func defaultHubOptions() *options {
return &options{
ctx: context.Background(),
}
}
// Option func is for applying any params to hub options
type Option func(options *options)
func WithContext(ctx context.Context) Option {
return func(o *options) {
o.ctx = ctx
}
}
func WithBlockchain(bcr blockchain.Blockchainer) Option {
return func(o *options) {
o.bcr = bcr
}
}
func WithMarket(mp pb.MarketClient) Option {
return func(o *options) {
o.market = mp
}
}
func WithLocator(loc pb.LocatorClient) Option {
return func(o *options) {
o.locator = loc
}
}
func WithPrivateKey(k *ecdsa.PrivateKey) Option {
return func(o *options) {
o.ethKey = k
o.ethAddr = util.PubKeyToAddr(k.PublicKey)
}
}
func WithVersion(v string) Option {
return func(o *options) {
o.version = v
}
}
func WithCreds(creds credentials.TransportCredentials) Option {
return func(o *options) {
o.creds = creds
}
}
func WithCertRotator(rot util.HitlessCertRotator) Option {
return func(o *options) {
o.rot = rot
}
}
func WithCluster(cl Cluster, evt <-chan ClusterEvent) Option {
return func(o *options) {
o.cluster = cl
o.clusterEvents = evt
}
}