chore: avoid unneeded map copy when close connection in restful api

This commit is contained in:
wwqgtxx
2023-06-26 17:46:14 +08:00
parent 2284acce94
commit 42ef4fedfa
4 changed files with 24 additions and 18 deletions

View File

@ -73,20 +73,20 @@ func getConnections(w http.ResponseWriter, r *http.Request) {
func closeConnection(w http.ResponseWriter, r *http.Request) {
id := chi.URLParam(r, "id")
snapshot := statistic.DefaultManager.Snapshot()
for _, c := range snapshot.Connections {
statistic.DefaultManager.ConnectionsRange(func(c statistic.Tracker) bool {
if id == c.ID() {
c.Close()
break
_ = c.Close()
return false
}
}
return true
})
render.NoContent(w, r)
}
func closeAllConnections(w http.ResponseWriter, r *http.Request) {
snapshot := statistic.DefaultManager.Snapshot()
for _, c := range snapshot.Connections {
c.Close()
}
statistic.DefaultManager.ConnectionsRange(func(c statistic.Tracker) bool {
_ = c.Close()
return true
})
render.NoContent(w, r)
}