diff --git a/controller/tcp.go b/controller/tcp.go index 9337b37..9d53129 100644 --- a/controller/tcp.go +++ b/controller/tcp.go @@ -1,6 +1,7 @@ package controller import ( + "github.com/gin-gonic/gin" "log" "net" ) @@ -29,8 +30,22 @@ func PushServerTcp(str []byte){ _,err:=conn.Write(str) log.Println(ip,err) if err!=nil{ + conn.Close() delete(clientTcpList,ip) //clientTcpList=append(clientTcpList[:index],clientTcpList[index+1:]...) } } +} +func DeleteOnlineTcp(c *gin.Context) { + ip:=c.Query("ip") + for ipkey,conn :=range clientTcpList{ + if ip==ipkey{ + conn.Close() + delete(clientTcpList,ip) + } + } + c.JSON(200, gin.H{ + "code": 200, + "msg": "ok", + }) } \ No newline at end of file diff --git a/main.go b/main.go index 5551ceb..900ac89 100644 --- a/main.go +++ b/main.go @@ -104,6 +104,7 @@ func main() { engine.GET("/mysql",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.MysqlGetConf) engine.POST("/mysql",middleware.JwtApiMiddleware,middleware.RbacAuth, controller.MysqlSetConf) engine.GET("/visitors_online", controller.GetVisitorOnlines) + engine.GET("/clear_online_tcp", controller.DeleteOnlineTcp) engine.POST("/visitor",controller.PostVisitor) engine.GET("/visitor",middleware.JwtApiMiddleware, controller.GetVisitor) engine.GET("/visitors",middleware.JwtApiMiddleware, controller.GetVisitors)