From c249d12af7de8e095a544c7f392a6b92f41bec71 Mon Sep 17 00:00:00 2001 From: naiba Date: Fri, 20 May 2022 09:03:58 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20`dashboard=20v0.13.17`=20fix=20i?= =?UTF-8?q?ndexOf=20element=20in=20slice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- cmd/dashboard/controller/member_api.go | 32 +++++++++++++++----------- service/singleton/singleton.go | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 6dae906..08dab5c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
LOGO designed by 熊大 .

-    +   

:trollface: Nezha Monitoring self-hosted lightweight monitoring and operation system. Supports system status, HTTP (SSL certificate change, upcoming expiration, expiration), TCP, Ping monitoring and alerting, execute scheduled tasks and web terminal.

diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go index c446e71..bda8ec7 100644 --- a/cmd/dashboard/controller/member_api.go +++ b/cmd/dashboard/controller/member_api.go @@ -179,17 +179,19 @@ func (ma *memberAPI) delete(c *gin.Context) { tag := singleton.ServerList[id].Tag delete(singleton.SecretToID, singleton.ServerList[id].Secret) delete(singleton.ServerList, id) - index := 0 - for index < len(singleton.ServerTagToIDList[tag]) { - if singleton.ServerTagToIDList[tag][index] == id { + index := -1 + for i := 0; i < len(singleton.ServerTagToIDList[tag]); i++ { + if singleton.ServerTagToIDList[tag][i] == id { break } - index++ + index = i } - // 删除旧 Tag-ID 绑定关系 - singleton.ServerTagToIDList[tag] = append(singleton.ServerTagToIDList[tag][:index], singleton.ServerTagToIDList[tag][index+1:]...) - if len(singleton.ServerTagToIDList[tag]) == 0 { - delete(singleton.ServerTagToIDList, tag) + if index > -1 { + // 删除旧 Tag-ID 绑定关系 + singleton.ServerTagToIDList[tag] = append(singleton.ServerTagToIDList[tag][:index], singleton.ServerTagToIDList[tag][index+1:]...) + if len(singleton.ServerTagToIDList[tag]) == 0 { + delete(singleton.ServerTagToIDList, tag) + } } singleton.ServerLock.Unlock() singleton.ReSortServer() @@ -323,15 +325,17 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) { } // 如果修改了Tag if s.Tag != singleton.ServerList[s.ID].Tag { - index := 0 - for index < len(singleton.ServerTagToIDList[s.Tag]) { - if singleton.ServerTagToIDList[s.Tag][index] == s.ID { + index := -1 + for i := 0; i < len(singleton.ServerTagToIDList[s.Tag]); i++ { + if singleton.ServerTagToIDList[s.Tag][i] == s.ID { break } - index++ + index = i + } + if index > -1 { + // 删除旧 Tag-ID 绑定关系 + singleton.ServerTagToIDList[singleton.ServerList[s.ID].Tag] = append(singleton.ServerTagToIDList[singleton.ServerList[s.ID].Tag][:index], singleton.ServerTagToIDList[singleton.ServerList[s.ID].Tag][index+1:]...) } - // 删除旧 Tag-ID 绑定关系 - singleton.ServerTagToIDList[singleton.ServerList[s.ID].Tag] = append(singleton.ServerTagToIDList[singleton.ServerList[s.ID].Tag][:index], singleton.ServerTagToIDList[singleton.ServerList[s.ID].Tag][index+1:]...) // 设置新的 Tag-ID 绑定关系 singleton.ServerTagToIDList[s.Tag] = append(singleton.ServerTagToIDList[s.Tag], s.ID) if len(singleton.ServerTagToIDList[s.Tag]) == 0 { diff --git a/service/singleton/singleton.go b/service/singleton/singleton.go index 5729a2d..c48fd64 100644 --- a/service/singleton/singleton.go +++ b/service/singleton/singleton.go @@ -12,7 +12,7 @@ import ( "github.com/naiba/nezha/pkg/utils" ) -var Version = "v0.13.16" // !!记得修改 README 中的 badge 版本!! +var Version = "v0.13.17" // !!记得修改 README 中的 badge 版本!! var ( Conf *model.Config