neko/pkg/types/websocket.go
2022-03-20 11:43:00 +01:00

29 lines
539 B
Go

package types
import (
"encoding/json"
"net/http"
)
type WebSocketMessage struct {
Event string `json:"event"`
Payload json.RawMessage `json:"payload"`
}
type WebSocketHandler func(Session, WebSocketMessage) bool
type CheckOrigin func(r *http.Request) bool
type WebSocketPeer interface {
Send(event string, payload interface{})
Ping() error
Destroy(reason string)
}
type WebSocketManager interface {
Start()
Shutdown() error
AddHandler(handler WebSocketHandler)
Upgrade(checkOrigin CheckOrigin) RouterHandler
}