Documentation
¶
Index ¶
- Constants
- Variables
- func PeriodicWrite(c *gin.Context, interval time.Duration, get func() (any, error), ...)
- type DeduplicateFunc
- type Manager
- func (cm *Manager) Close()
- func (cm *Manager) Context() context.Context
- func (cm *Manager) Done() <-chan struct{}
- func (m *Manager) NewReader() io.Reader
- func (cm *Manager) NewWriter(msgType int) io.Writer
- func (cm *Manager) PeriodicWrite(interval time.Duration, getData func() (any, error), ...) error
- func (cm *Manager) ReadBinary(timeout time.Duration) ([]byte, error)
- func (cm *Manager) ReadJSON(out any, timeout time.Duration) error
- func (cm *Manager) WriteData(typ int, data []byte, timeout time.Duration) error
- func (cm *Manager) WriteJSON(data any, timeout time.Duration) error
- type Reader
- type Writer
Constants ¶
const ( TextMessage = websocket.TextMessage BinaryMessage = websocket.BinaryMessage )
Variables ¶
var ( ErrReadTimeout = errors.New("read timeout") ErrWriteTimeout = errors.New("write timeout") )
Functions ¶
func PeriodicWrite ¶
Types ¶
type DeduplicateFunc ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles WebSocket connection state and ping-pong
func NewManagerWithUpgrade ¶
NewManagerWithUpgrade upgrades the HTTP connection to a WebSocket connection and returns a Manager. If the upgrade fails, the error is returned. If the upgrade succeeds, the Manager is returned.
To use a custom upgrader, set the "upgrader" context value to the upgrader.
func (*Manager) Close ¶
func (cm *Manager) Close()
Close closes the connection and cancels the context
func (*Manager) Done ¶
func (cm *Manager) Done() <-chan struct{}
Done returns a channel that is closed when the context is done or the connection is closed
func (*Manager) PeriodicWrite ¶
func (cm *Manager) PeriodicWrite(interval time.Duration, getData func() (any, error), deduplicate ...DeduplicateFunc) error
Periodic writes data to the connection periodically, with deduplication. If the connection is closed, the error is returned. If the write timeout is reached, ErrWriteTimeout is returned.
func (*Manager) ReadJSON ¶
ReadJSON reads a JSON message from the connection and unmarshals it into the provided struct with sonic If the connection is closed, the error is returned. If the message fails to unmarshal, the error is returned. If the read timeout is reached, ErrReadTimeout is returned.