Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/websocket/socket.go

38 lines
624 B
Go
Raw Normal View History

2020-01-25 04:47:37 +13:00
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()
}