mirror of
https://github.com/m1k1o/neko.git
synced 2025-06-13 00:04:08 +02:00
fixes #14
This commit is contained in:
parent
a0866a4ab9
commit
e3a73aa264
26 changed files with 1154 additions and 934 deletions
37
server/internal/websocket/socket.go
Normal file
37
server/internal/websocket/socket.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package websocket
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type WebSocket struct {
|
||||
id string
|
||||
connection *websocket.Conn
|
||||
}
|
||||
|
||||
func (socket *WebSocket) Address() *string {
|
||||
remote := socket.connection.RemoteAddr()
|
||||
address := strings.SplitN(remote.String(), ":", -1)
|
||||
if len(address[0]) < 1 {
|
||||
return nil
|
||||
}
|
||||
return &address[0]
|
||||
}
|
||||
|
||||
func (socket *WebSocket) Send(v interface{}) error {
|
||||
if socket.connection == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return socket.connection.WriteJSON(v)
|
||||
}
|
||||
|
||||
func (socket *WebSocket) Destroy() error {
|
||||
if socket.connection == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return socket.connection.Close()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue