-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkinfo_crdb.go
68 lines (61 loc) · 1.32 KB
/
linkinfo_crdb.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
66
67
68
package dbcommon
import (
"fmt"
"github.com/xormplus/xorm"
)
/*************************
* author: Dev0026
* createTime: 19-5-9
* updateTime: 19-5-9
* description:
*************************/
type cockdbInfo struct {
UserName string
UserPasswd string
HostInfo string
Platform string
}
func initCRDBInfo(engine *xorm.Engine) error {
var crdbInfo = make([]*cockdbInfo, 0)
err := engine.SQL("select user_name, user_passwd, host_info, platform from cockdb_info").Find(&crdbInfo)
if nil != err {
return fmt.Errorf("initCRDBInfo err: %v", err)
}
for _, one := range crdbInfo {
err = decodeCRDBInfo(one)
if nil != err {
return err
}
key := getCRDBKey(one.Platform)
linkMap.Store(key, one)
}
return nil
}
func GetCRDBInfo(platform string) (*cockdbInfo, bool) {
key := getCRDBKey(platform)
val, ok := linkMap.Load(key)
if ok {
return val.(*cockdbInfo), ok
}
return nil, ok
}
func getCRDBKey(platform string) string {
return fmt.Sprintf("crdbinfo_%v", platform)
}
func decodeCRDBInfo(info *cockdbInfo) (err error) {
info.UserName, err = RsaDecrypt(info.UserName)
if nil != err {
return err
}
if info.UserPasswd != "" {
info.UserPasswd, err = RsaDecrypt(info.UserPasswd)
if nil != err {
return err
}
}
info.HostInfo, err = RsaDecrypt(info.HostInfo)
if nil != err {
return err
}
return nil
}