forked from googollee/go-socket.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter_options.go
62 lines (50 loc) · 1.07 KB
/
adapter_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 socketio
import "fmt"
// RedisAdapterOptions is configuration to create new adapter
type RedisAdapterOptions struct {
// deprecated. Usage Addr options
Host string
// deprecated. Usage Addr options
Port string
Addr string
Prefix string
Network string
Password string
}
func (ro *RedisAdapterOptions) getAddr() string {
if ro.Addr == "" {
ro.Addr = fmt.Sprintf("%s:%s", ro.Host, ro.Port)
}
return ro.Addr
}
func defaultOptions() *RedisAdapterOptions {
return &RedisAdapterOptions{
Addr: "127.0.0.1:6379",
Prefix: "socket.io",
Network: "tcp",
}
}
func getOptions(opts *RedisAdapterOptions) *RedisAdapterOptions {
options := defaultOptions()
if opts != nil {
if opts.Host != "" {
options.Host = opts.Host
}
if opts.Port != "" {
options.Port = opts.Port
}
if opts.Addr != "" {
options.Addr = opts.Addr
}
if opts.Prefix != "" {
options.Prefix = opts.Prefix
}
if opts.Network != "" {
options.Network = opts.Network
}
if len(opts.Password) > 0 {
options.Password = opts.Password
}
}
return options
}