diff --git a/backend/services/node.go b/backend/services/node.go index edaf9f16..d14ce4ae 100644 --- a/backend/services/node.go +++ b/backend/services/node.go @@ -171,7 +171,7 @@ func UpdateNodeData() { //先获取所有Redis的nodekey list, _ := database.RedisClient.HKeys("nodes") - if i := utils.Contains(list, key); i != -1 { + if i := utils.Contains(list, key); i == false { // 构造节点数据 data := Data{ Key: key, diff --git a/backend/utils/helpers.go b/backend/utils/helpers.go index ce29e4b7..e181c66c 100644 --- a/backend/utils/helpers.go +++ b/backend/utils/helpers.go @@ -42,19 +42,19 @@ func Close(c io.Closer) { } } -func Contains(array interface{}, val interface{}) (index int) { - index = -1 +func Contains(array interface{}, val interface{}) (fla bool) { + fla = false switch reflect.TypeOf(array).Kind() { case reflect.Slice: { s := reflect.ValueOf(array) for i := 0; i < s.Len(); i++ { if reflect.DeepEqual(val, s.Index(i).Interface()) { - index = i + fla = true return } } } } return -} \ No newline at end of file +}