-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
32 lines (29 loc) · 865 Bytes
/
service.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
package redis
import (
"golang.org/x/crypto/ssh"
"strings"
)
type Config struct {
Address string `json:"address"`
Auth string `json:"auth"`
Username string `json:"username"`
CertPath string `json:"certPath"`
Servers []string `json:"servers"`
SSHClient *ssh.Client `json:"-"`
}
// New 创建Redis服务
func New(config *Config) (service IService, err error) {
if !strings.Contains(config.Address, ",") && !strings.Contains(config.Address, ";") {
service, err = NewRedisService(config)
} else {
if strings.Contains(config.Address, ",") {
config.Servers = strings.Split(config.Address, ",")
} else if strings.Contains(config.Address, ";") {
config.Servers = strings.Split(config.Address, ";")
} else {
config.Servers = []string{config.Address}
}
service, err = NewClusterService(config)
}
return
}