forked from micro/micro
/
options.go
executable file
·54 lines (44 loc) · 951 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
package broker
import (
"context"
"crypto/tls"
"github.com/2637309949/micro/v3/service/broker"
)
type optionsKey struct{}
// Options which are used to configure the redis broker
type Options struct {
Address string
User string
Password string
TLSConfig *tls.Config
}
// Option is a function which configures options
type Option func(o *Options)
func Address(addr string) Option {
return func(o *Options) {
o.Address = addr
}
}
func User(user string) Option {
return func(o *Options) {
o.User = user
}
}
func Password(password string) Option {
return func(o *Options) {
o.Password = password
}
}
func TLSConfig(tlsConfig *tls.Config) Option {
return func(o *Options) {
o.TLSConfig = tlsConfig
}
}
func RedisOptions(opts Options) broker.Option {
return func(o *broker.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, optionsKey{}, opts)
}
}