You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
hexmap/server/websocket/shared.go

42 lines
1.5 KiB

package websocket
import (
"github.com/gorilla/websocket"
"go.uber.org/zap/zapcore"
)
const (
PingData string = "are you still there?"
GoodbyeType = "GOODBYE"
)
var StandardClientCloseTypes = []int{websocket.CloseNormalClosure, websocket.CloseGoingAway, websocket.CloseAbnormalClosure}
// SocketClosed is synthesized when a client closes the WebSocket connection, or sent to the write process to write a
// WebSocket close message.
// Sending a SocketClosed on a channel causes that channel to be closed right after.
type SocketClosed struct {
// Code is the status code given (or which should be given) in the close message.
Code int `json:"code"`
// Text is the reason text given (or which should be given) in the close message. Max 123 characters.
Text string `json:"text"`
// Error may be an error that resulted in the closure of the socket. It will be set only if the connection was cut
// by a condition other than receiving a close message; if it is set, Code and Text will both be zeroed.
// Will not be written by the writer; only useful when it's returned from the reader.
Error error `json:"error"`
}
func (c SocketClosed) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
encoder.AddString("type", GoodbyeType)
encoder.AddInt16("code", int16(c.Code))
encoder.AddString("text", c.Text)
if c.Error != nil {
encoder.AddString("error", c.Error.Error())
}
return nil
}
func (c SocketClosed) ServerType() ServerMessageType {
return GoodbyeType
}