updated ipbl websocket feat

This commit is contained in:
Paul 2023-04-10 11:57:25 +02:00
parent abc02caf92
commit 447f756922
3 changed files with 12 additions and 11 deletions

View File

@ -3,7 +3,6 @@ package routers
import (
"context"
"fmt"
"log"
"net/http"
"strconv"
@ -87,7 +86,6 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
}
numinsert, numupdate, _ := models.InsertIPBulk(session, &ips)
msg = fmt.Sprintf("Inserted %d IP, Updated %d IP", numinsert, numupdate)
log.Println(msg)
return Result(c, err, msg)
})
e.POST("/event", func(c echo.Context) (err error) {

View File

@ -43,6 +43,15 @@ func WelcomeAgents(ws *websocket.Conn, welcome WSWelcome, t string) {
}
}
func gcConn(conn *websocket.Conn) (err error) {
for index, value := range LISTENERS {
if value.ConnectionPS == conn || value.ConnectionRR == conn {
delete(LISTENERS, index)
}
}
return err
}
type ConnectionInfo struct {
ConnectionPS *websocket.Conn
ConnectionRR *websocket.Conn
@ -52,12 +61,3 @@ type ConnectionInfo struct {
type WSWelcome struct {
Hostname string
}
func gcConn(conn *websocket.Conn, t string) (err error) {
for index, value := range LISTENERS {
if value.ConnectionPS == conn {
delete(LISTENERS, index)
}
}
return err
}

View File

@ -80,11 +80,14 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
err = websocket.Message.Send(value.ConnectionPS, msg)
if err != nil {
log.Println(err)
}
}
default:
}
gcConn(ws)
err = websocket.Message.Send(ws, "OK")
if err != nil {
log.Println(err)