-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathoptions.go
53 lines (45 loc) · 1.03 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
package minisentinel
import (
"github.com/alicebob/miniredis/v2"
)
// Option - how Options are passed as arguments
type Option func(*Options)
// Options = how options are represented
type Options struct {
masterName string
master *miniredis.Miniredis
replica *miniredis.Miniredis
}
func getDefaultOptions() Options {
return Options{
masterName: "mymaster",
master: nil,
replica: nil,
}
}
// WithMasterName - set the name of the master
func WithMasterName(name string) Option {
return func(o *Options) {
o.masterName = name
}
}
// WithMaster - set the primary miniredis for the sentinel
func WithMaster(m *miniredis.Miniredis) Option {
return func(o *Options) {
o.master = m
}
}
// WithReplica - set the replicas for sentinel
func WithReplica(replica *miniredis.Miniredis) Option {
return func(o *Options) {
o.replica = replica
}
}
// GetOpts - iterate the inbound Options and return a struct
func GetOpts(opt ...Option) Options {
opts := getDefaultOptions()
for _, o := range opt {
o(&opts)
}
return opts
}