修复节点名称

This commit is contained in:
marvzhang
2020-03-08 17:10:13 +08:00
parent 801b100197
commit cc81b80397

View File

@@ -15,6 +15,7 @@ import (
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
"github.com/gomodule/redigo/redis"
"github.com/spf13/viper"
"runtime/debug"
"time"
)
@@ -104,6 +105,19 @@ func UpdateNodeStatus() {
model.ResetNodeStatusToOffline(list)
}
func getNodeName(data *Data) string {
registerType := viper.GetString("server.register.type")
if registerType == constants.RegisterTypeMac {
return data.Ip
} else if registerType == constants.RegisterTypeIp {
return data.Ip
} else if registerType == constants.RegisterTypeHostname {
return data.Hostname
} else {
return data.Ip
}
}
// 处理节点信息
func handleNodeInfo(key string, data *Data) {
// 添加同步锁
@@ -122,7 +136,7 @@ func handleNodeInfo(key string, data *Data) {
// 数据库不存在该节点
node = model.Node{
Key: key,
Name: data.Ip,
Name: getNodeName(data),
Ip: data.Ip,
Port: "8000",
Mac: data.Mac,