liuxiaolong
2021-06-02 e67dc008802aafb884dc94da054f2090da4005e2
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
package bhomedbapi
 
import (
    "basic.com/valib/bhshmq.git/proto/source/bhome_msg"
)
 
//Factory new client
func NewClient(opts ...IOption) Client {
    opt := defaultOption()
    for _,o := range opts {
        o.apply(&opt)
    }
    return &SBusClient{
        nodes: opt.nodes,
    }
}
 
type Option struct {
    nodes []*bhome_msg.MsgQueryTopicReply_BHNodeAddress
}
 
type IOption interface {
    apply(*Option)
}
 
type funcOption struct {
    f func(*Option)
}
 
func (fo *funcOption) apply(o *Option) {
    fo.f(o)
}
 
func newFuncOption(f func(*Option)) *funcOption {
    return &funcOption{
        f:f,
    }
}
 
func WithNodes(nodeArr []*bhome_msg.MsgQueryTopicReply_BHNodeAddress) IOption {
    return newFuncOption(func(o *Option) {
        o.nodes = nodeArr
    })
}
 
func defaultOption() Option {
    return Option{
 
    }
}