🐛 dashboard v0.13.17 fix indexOf element in slice

This commit is contained in:
naiba 2022-05-20 09:03:58 +08:00
parent ddb05a5aa0
commit c249d12af7
3 changed files with 20 additions and 16 deletions

View File

@ -4,7 +4,7 @@
<br> <br>
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small> <small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
<br><br> <br><br>
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.13.16&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.10.2-brightgreen?style=for-the-badge&logo=linux"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.13.17&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.10.2-brightgreen?style=for-the-badge&logo=linux">
<br> <br>
<br> <br>
<p>:trollface: <b>Nezha Monitoring</b> self-hosted lightweight monitoring and operation system. Supports system status, HTTP (SSL certificate change, upcoming expiration, expiration), TCP, Ping <b>monitoring</b> and <b>alerting</b>, execute scheduled tasks and <b>web terminal</b>.</p> <p>:trollface: <b>Nezha Monitoring</b> self-hosted lightweight monitoring and operation system. Supports system status, HTTP (SSL certificate change, upcoming expiration, expiration), TCP, Ping <b>monitoring</b> and <b>alerting</b>, execute scheduled tasks and <b>web terminal</b>.</p>

View File

@ -179,18 +179,20 @@ func (ma *memberAPI) delete(c *gin.Context) {
tag := singleton.ServerList[id].Tag tag := singleton.ServerList[id].Tag
delete(singleton.SecretToID, singleton.ServerList[id].Secret) delete(singleton.SecretToID, singleton.ServerList[id].Secret)
delete(singleton.ServerList, id) delete(singleton.ServerList, id)
index := 0 index := -1
for index < len(singleton.ServerTagToIDList[tag]) { for i := 0; i < len(singleton.ServerTagToIDList[tag]); i++ {
if singleton.ServerTagToIDList[tag][index] == id { if singleton.ServerTagToIDList[tag][i] == id {
break break
} }
index++ index = i
} }
if index > -1 {
// 删除旧 Tag-ID 绑定关系 // 删除旧 Tag-ID 绑定关系
singleton.ServerTagToIDList[tag] = append(singleton.ServerTagToIDList[tag][:index], singleton.ServerTagToIDList[tag][index+1:]...) singleton.ServerTagToIDList[tag] = append(singleton.ServerTagToIDList[tag][:index], singleton.ServerTagToIDList[tag][index+1:]...)
if len(singleton.ServerTagToIDList[tag]) == 0 { if len(singleton.ServerTagToIDList[tag]) == 0 {
delete(singleton.ServerTagToIDList, tag) delete(singleton.ServerTagToIDList, tag)
} }
}
singleton.ServerLock.Unlock() singleton.ServerLock.Unlock()
singleton.ReSortServer() singleton.ReSortServer()
// 删除循环流量状态中的此服务器相关的记录 // 删除循环流量状态中的此服务器相关的记录
@ -323,15 +325,17 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
} }
// 如果修改了Tag // 如果修改了Tag
if s.Tag != singleton.ServerList[s.ID].Tag { if s.Tag != singleton.ServerList[s.ID].Tag {
index := 0 index := -1
for index < len(singleton.ServerTagToIDList[s.Tag]) { for i := 0; i < len(singleton.ServerTagToIDList[s.Tag]); i++ {
if singleton.ServerTagToIDList[s.Tag][index] == s.ID { if singleton.ServerTagToIDList[s.Tag][i] == s.ID {
break break
} }
index++ index = i
} }
if index > -1 {
// 删除旧 Tag-ID 绑定关系 // 删除旧 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:]...) 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 绑定关系 // 设置新的 Tag-ID 绑定关系
singleton.ServerTagToIDList[s.Tag] = append(singleton.ServerTagToIDList[s.Tag], s.ID) singleton.ServerTagToIDList[s.Tag] = append(singleton.ServerTagToIDList[s.Tag], s.ID)
if len(singleton.ServerTagToIDList[s.Tag]) == 0 { if len(singleton.ServerTagToIDList[s.Tag]) == 0 {

View File

@ -12,7 +12,7 @@ import (
"github.com/naiba/nezha/pkg/utils" "github.com/naiba/nezha/pkg/utils"
) )
var Version = "v0.13.16" // !!记得修改 README 中的 badge 版本!! var Version = "v0.13.17" // !!记得修改 README 中的 badge 版本!!
var ( var (
Conf *model.Config Conf *model.Config