Documentation
¶
Overview ¶
Copyright (c) 2025 Jon Webb. All rights reserved.
Socket hub implementation is inspired by https://github.com/olahol/melody. Copyright (c) 2015 Ola Holmström. All rights reserved. Licensed under the BSD 2-Clause License.
Index ¶
- Constants
- Variables
- type Hub
- func (h *Hub) Broadcast(data []byte) error
- func (h *Hub) BroadcastBinary(data []byte) error
- func (h *Hub) BroadcastBinaryFilter(data []byte, fn func(*Session) bool) error
- func (h *Hub) BroadcastBinaryFilterWithDeadline(data []byte, fn func(*Session) bool, deadline time.Duration) error
- func (h *Hub) BroadcastBinaryMultiple(data []byte, sessions []*Session) error
- func (h *Hub) BroadcastBinaryWithDeadline(data []byte, deadline time.Duration) error
- func (h *Hub) BroadcastFilter(data []byte, fn func(*Session) bool) error
- func (h *Hub) BroadcastFilterWithDeadline(data []byte, fn func(*Session) bool, deadline time.Duration) error
- func (h *Hub) BroadcastMultiple(data []byte, sessions []*Session) error
- func (h *Hub) BroadcastWithDeadline(data []byte, deadline time.Duration) error
- func (h *Hub) Close() error
- func (h *Hub) CloseWithMessage(data []byte) error
- func (h *Hub) FormatCloseMessage(code int, text string) []byte
- func (h *Hub) HandleRequest(w http.ResponseWriter, req *http.Request) error
- func (h *Hub) HandleRequestWithValues(w http.ResponseWriter, req *http.Request, values map[string]any) error
- func (h *Hub) IsClosed() bool
- func (h *Hub) Len() int
- func (h *Hub) Sessions() ([]*Session, error)
- type Session
- func (s *Session) Close() error
- func (s *Session) CloseWithMessage(data []byte) error
- func (s *Session) Get(key string) (value any, ok bool)
- func (s *Session) IsClosed() bool
- func (s *Session) Set(key string, value any)
- func (s *Session) Unset(key string)
- func (s *Session) WebsocketConn() *websocket.Conn
- func (s *Session) Write(data []byte) error
- func (s *Session) WriteBinary(data []byte) error
- func (s *Session) WriteBinaryWithDeadline(data []byte, deadline time.Duration) error
- func (s *Session) WriteWithDeadline(data []byte, deadline time.Duration) error
Constants ¶
View Source
const ( CloseNormalClosure = 1000 CloseGoingAway = 1001 CloseProtocolError = 1002 CloseUnsupportedData = 1003 CloseNoStatusReceived = 1005 CloseAbnormalClosure = 1006 CloseInvalidFramePayloadData = 1007 ClosePolicyViolation = 1008 CloseMessageTooBig = 1009 CloseMandatoryExtension = 1010 CloseInternalServerErr = 1011 CloseServiceRestart = 1012 CloseTryAgainLater = 1013 CloseTLSHandshake = 1015 )
Close codes defined in RFC 6455, section 11.7. Duplicate of codes from gorilla/websocket for convenience.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub struct {
Upgrader *websocket.Upgrader
WriteWait time.Duration
PongWait time.Duration
PingPeriod time.Duration
MaxMessageSize int64
MessageBufferSize int
ConcurrentHandling bool
HandleMessage messageHandlerFunc
HandleBinaryMessage messageHandlerFunc
HandleMessageSent messageHandlerFunc
HandleBinaryMessageSent messageHandlerFunc
HandleError errorHandlerFunc
HandleClose closeHandlerFunc
HandleConnect sessionHandlerFunc
HandleDisconnect sessionHandlerFunc
HandlePong sessionHandlerFunc
// contains filtered or unexported fields
}
func (*Hub) BroadcastBinary ¶
func (*Hub) BroadcastBinaryFilter ¶
func (*Hub) BroadcastBinaryFilterWithDeadline ¶
func (*Hub) BroadcastBinaryMultiple ¶
func (*Hub) BroadcastBinaryWithDeadline ¶
func (*Hub) BroadcastFilter ¶
func (*Hub) BroadcastFilterWithDeadline ¶
func (*Hub) BroadcastMultiple ¶
func (*Hub) BroadcastWithDeadline ¶
func (*Hub) CloseWithMessage ¶
func (*Hub) HandleRequest ¶
func (*Hub) HandleRequestWithValues ¶
type Session ¶
type Session struct {
Req *http.Request
Values map[string]any
// contains filtered or unexported fields
}
func (*Session) CloseWithMessage ¶
func (*Session) WebsocketConn ¶
func (*Session) WriteBinary ¶
func (*Session) WriteBinaryWithDeadline ¶
Click to show internal directories.
Click to hide internal directories.