/
lb_options.go
53 lines (45 loc) · 1.28 KB
/
lb_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
package ConsistentHash_trpcgo
import (
"context"
"time"
)
// Options is the call options.
type Options struct {
Ctx context.Context // request context
Interval time.Duration // refresh interval
Namespace string // namespace
LoadBalanceType string // load balance type
Replicas int // virtual node coefficient of consistent hash
}
// Option modifies the Options.
type Option func(*Options)
// WithContext returns an Option which set request ctx.
func WithContext(ctx context.Context) Option {
return func(o *Options) {
o.Ctx = ctx
}
}
// WithNamespace returns an Option which set namespace.
func WithNamespace(namespace string) Option {
return func(opts *Options) {
opts.Namespace = namespace
}
}
// WithInterval returns an Option which set load balance refresh interval.
func WithInterval(interval time.Duration) Option {
return func(opts *Options) {
opts.Interval = interval
}
}
// WithReplicas returns an Option which set the virtual node coefficient.
func WithReplicas(r int) Option {
return func(o *Options) {
o.Replicas = r
}
}
// WithLoadBalanceType returns an Option which set load balance type.
func WithLoadBalanceType(name string) Option {
return func(opts *Options) {
opts.LoadBalanceType = name
}
}