Dealer/pkg/internal/server/api/ws.go
LittleSheep 466b240e95
Some checks failed
release-nightly / build-docker (push) Has been cancelled
🎉 Initial Commit
2024-07-14 20:25:30 +08:00

30 lines
671 B
Go

package api
import (
"git.solsynth.dev/hydrogen/dealer/pkg/internal/models"
"git.solsynth.dev/hydrogen/dealer/pkg/internal/services"
"github.com/gofiber/contrib/websocket"
"github.com/rs/zerolog/log"
)
func listenWebsocket(c *websocket.Conn) {
user := c.Locals("user").(models.Account)
// Push connection
services.ClientRegister(user, c)
log.Debug().Uint("user", user.ID).Msg("New websocket connection established...")
// Event loop
var err error
for {
if _, _, err = c.ReadMessage(); err != nil {
break
}
}
// Pop connection
services.ClientUnregister(user, c)
log.Debug().Uint("user", user.ID).Msg("A websocket connection disconnected...")
}