1
0
mirror of https://github.com/nxshock/gron.git synced 2024-11-27 03:41:00 +05:00

Compare commits

..

No commits in common. "b6e32d3b9821bf3302d52e11edd652c428587d51" and "252141ae01108f780db0a6d7c63497d36119a92a" have entirely different histories.

3 changed files with 6 additions and 34 deletions

View File

@ -16,7 +16,7 @@ import (
)
type WsConnections struct {
connections map[*WsConnection]struct{}
connections map[*websocket.Conn]struct{}
mutex sync.Mutex
}
@ -24,24 +24,19 @@ func (wc *WsConnections) Add(c *websocket.Conn) {
wc.mutex.Lock()
defer wc.mutex.Unlock()
wc.connections[NewWsConnection(c)] = struct{}{}
wc.connections[c] = struct{}{}
}
func (wc *WsConnections) Delete(c *websocket.Conn) {
wc.mutex.Lock()
defer wc.mutex.Unlock()
for k := range wc.connections {
if k.w == c {
delete(wc.connections, k)
break
}
}
delete(wc.connections, c)
}
func (wc *WsConnections) Send(message interface{}) {
for conn := range wc.connections {
go func(conn *WsConnection) { _ = conn.Send(message) }(conn)
go func(conn *websocket.Conn) { _ = conn.WriteJSON(message) }(conn)
}
}
@ -54,7 +49,7 @@ var upgrader = websocket.Upgrader{
}
var wsConnections = &WsConnections{
connections: make(map[*WsConnection]struct{})}
connections: make(map[*websocket.Conn]struct{})}
func httpServer(listenAddress string) {
if listenAddress == "none" {

View File

@ -1 +1 @@
go build -ldflags "-s -w" -buildmode=pie -trimpath
go build -ldflags "-s -w -H windowsgui" -buildmode=pie -trimpath

View File

@ -1,23 +0,0 @@
package main
import (
"sync"
"github.com/gorilla/websocket"
)
type WsConnection struct {
w *websocket.Conn
mu sync.Mutex
}
func NewWsConnection(w *websocket.Conn) *WsConnection {
return &WsConnection{w: w}
}
func (w *WsConnection) Send(message any) error {
w.mu.Lock()
defer w.mu.Unlock()
return w.w.WriteJSON(message)
}