mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
🚀 dashboard v0.14.7 with agent v0.14.4
This commit is contained in:
25
pkg/websocketx/safe_conn.go
Normal file
25
pkg/websocketx/safe_conn.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package websocketx
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type Conn struct {
|
||||
*websocket.Conn
|
||||
writeLock sync.Mutex
|
||||
}
|
||||
|
||||
func (conn *Conn) WriteMessage(msgType int, data []byte) error {
|
||||
conn.writeLock.Lock()
|
||||
defer conn.writeLock.Unlock()
|
||||
var err error
|
||||
lo.TryCatchWithErrorValue(func() error {
|
||||
return conn.Conn.WriteMessage(msgType, data)
|
||||
}, func(res any) {
|
||||
err = res.(error)
|
||||
})
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user