-
Notifications
You must be signed in to change notification settings - Fork 197
/
initial.go
65 lines (55 loc) · 1.42 KB
/
initial.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
63
64
65
package exchange
import (
"net"
"os"
"path/filepath"
"strings"
"github.com/jumpserver/koko/pkg/config"
"github.com/jumpserver/koko/pkg/logger"
)
var manager RoomManager
func Initial() {
conf := config.GetConf()
var (
err error
)
switch strings.ToLower(conf.ShareRoomType) {
case "redis":
existFile := func(path string) string {
if info, err2 := os.Stat(path); err2 == nil && !info.IsDir() {
return path
}
return ""
}
sslCaPath := filepath.Join(conf.CertsFolderPath, "redis_ca.crt")
sslCertPath := filepath.Join(conf.CertsFolderPath, "redis_client.crt")
sslKeyPath := filepath.Join(conf.CertsFolderPath, "redis_client.key")
manager, err = newRedisManager(Config{
Addr: net.JoinHostPort(conf.RedisHost, conf.RedisPort),
Password: conf.RedisPassword,
Clusters: conf.RedisClusters,
DBIndex: conf.RedisDBIndex,
SentinelPassword: conf.RedisSentinelPassword,
SentinelsHost: conf.RedisSentinelHosts,
UseSSL: conf.RedisUseSSL,
SSLCa: existFile(sslCaPath),
SSLCert: existFile(sslCertPath),
SSLKey: existFile(sslKeyPath),
})
default:
manager = newLocalManager()
}
logger.Infof("Exchange share room type: %s", conf.ShareRoomType)
if err != nil {
logger.Fatal(err)
}
}
func Register(r *Room) {
manager.Add(r)
}
func UnRegister(r *Room) {
manager.Delete(r)
}
func GetRoom(roomId string) *Room {
return manager.Get(roomId)
}