zhangzengfei
2024-02-05 78b0ffc543d78769580fa91842c8d635fe8c9405
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
69
70
71
72
73
74
75
76
77
78
79
80
package discovery
 
import (
    "basic.com/pubsub/cache.git/shardmap"
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/logger.git"
    "errors"
    "github.com/gogo/protobuf/proto"
    "sdkCompare/config"
    "sdkCompare/util"
)
 
const (
    SERVER_KEY = "SERVERINFO"
)
 
var cMap *shardmap.ShardMap
var withBus bool
 
func SetBus(wb bool) error {
    withBus = wb
    if !withBus {
        serverIp, _, e := util.GetLocalIP(config.Server.NetworkAdapter)
        if e != nil {
            return e
        }
        cMap = shardmap.New(uint8(32))
        cMap.Set(SERVER_KEY, protomsg.LocalConfig{
            AlarmIp:   serverIp,
            AlarmPort: 9200,
        })
    }
    return nil
}
 
func initCacheData(initChan chan bool) {
 
    initChan <- true
}
 
var newUpdateMsg = &protomsg.DbChangeMessage{}
 
func updateData(b []byte) {
    if err := proto.Unmarshal(b, newUpdateMsg); err != nil {
        logger.Debug("dbChangeMsg unmarshal err:", err)
        return
    }
    switch newUpdateMsg.Table {
    case protomsg.TableChanged_T_Server:
    default:
        logger.Debug("other updateData operation")
 
    }
}
 
func GetServerInfo() (conf protomsg.LocalConfig, err error) {
    config, b := cMap.Get(SERVER_KEY)
    if b {
        return config.(protomsg.LocalConfig), nil
    } else {
        return conf, errors.New("conf not found")
    }
}
 
// 判断一个数组是否包含另一个数组的所有元素
func arrayContains(list []string, arr []string) bool {
    c := 0
    if arr == nil || list == nil {
        return false
    }
    for _, s := range arr {
        for _, t := range list {
            if s == t {
                c++
                break
            }
        }
    }
    return c == len(arr)
}