From 7f84285421fcdb21e79d6214887e0dacb2331039 Mon Sep 17 00:00:00 2001 From: lyyyuna Date: Fri, 10 Sep 2021 14:47:03 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20rm=20only=20specific=20id?= =?UTF-8?q?=20in=20store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/server/api.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/server/api.go b/pkg/server/api.go index abd11b1..0a8a68b 100644 --- a/pkg/server/api.go +++ b/pkg/server/api.go @@ -58,10 +58,12 @@ func (gs *gocServer) removeAgents(c *gin.Context) { idQuery := c.Query("id") ifInIdMap := idMaps(idQuery) + errs := "" gs.agents.Range(func(key, value interface{}) bool { // check if id is in the query ids - if !ifInIdMap(key.(string)) { + id := key.(string) + if !ifInIdMap(id) { return true } @@ -70,13 +72,26 @@ func (gs *gocServer) removeAgents(c *gin.Context) { return false } + err := gs.removeAgentFromStore(id) + if err != nil { + log.Errorf("fail to remove agent: %v", id) + err := fmt.Errorf("fail to remove agent: %v, err: %v", id, err) + errs = errs + err.Error() + return true + } agent.closeConnection() gs.agents.Delete(key) return true }) - gs.removeAllAgentsFromStore() + if errs != "" { + c.JSON(http.StatusInternalServerError, gin.H{ + "msg": errs, + }) + } else { + c.JSON(http.StatusOK, nil) + } } // getProfiles get and merge all agents' informations