-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
62 lines (51 loc) · 974 Bytes
/
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
package chat
import (
"github.com/go-redis/redis"
"github.com/micro/go-micro/registry"
)
type Options struct {
Name string
Version string
Topic string
RedisOptions *redis.Options
RegistryOptions []registry.Option
}
type Option func(o *Options)
func newOptions(opts ...Option) Options {
opt := Options{
Name: DefaultName,
Version: DefaultVersion,
Topic: DefaultTopic,
}
for _, o := range opts {
o(&opt)
}
return opt
}
// Server name
func Name(n string) Option {
return func(o *Options) {
o.Name = n
}
}
// Version of the service
func Version(v string) Option {
return func(o *Options) {
o.Version = v
}
}
func Topic(v string) Option {
return func(o *Options) {
o.Topic = v
}
}
func RegistryOptions(opts ...registry.Option) Option {
return func(o *Options) {
o.RegistryOptions = opts
}
}
func RedisOptions(opts redis.Options) Option {
return func(o *Options) {
o.RedisOptions = &opts
}
}