ws

package
v0.0.0-...-0cc1b8c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Time allowed to write a message to the peer.
	WriteWait = 10 * time.Second

	// Time allowed to read the next pong message from the peer.
	PongWait = 60 * time.Second

	// Send pings to peer with this period. Must be less than pongWait.
	PingPeriod = (PongWait * 9) / 10

	// Maximum message size allowed from peer.
	MaxMessageSize = 512
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name string `json:"name"`
	Body string `json:"body"`
}

func NewCommand

func NewCommand(name string, body []byte) *Command

func (Command) BindJson

func (c Command) BindJson(obj any) error

func (Command) Marshal

func (c Command) Marshal() []byte

func (*Command) Unmarshal

func (c *Command) Unmarshal(data []byte) error

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(id ID, hub *Hub, socket *websocket.Conn) *Connection

func (*Connection) Broadcast

func (c *Connection) Broadcast(cmd *Command)

func (*Connection) ID

func (c *Connection) ID() ID

func (*Connection) Log

func (c *Connection) Log(log string)

func (*Connection) RegisterCloseHandler

func (c *Connection) RegisterCloseHandler(name string, handler Handler)

func (*Connection) Send

func (c *Connection) Send(to ID, cmd *Command)

func (*Connection) UnregisterCloseHandler

func (c *Connection) UnregisterCloseHandler(name string)

type Handler

type Handler func(*Connection, *Command)

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func NewHub

func NewHub(logger func(log string)) *Hub

func (*Hub) Accept

func (hub *Hub) Accept(w http.ResponseWriter, r *http.Request) (ID, error)

func (*Hub) Broadcast

func (h *Hub) Broadcast(cmd Command)

func (*Hub) RegisterHandler

func (h *Hub) RegisterHandler(name string, handler Handler)

func (*Hub) Relay

func (h *Hub) Relay(to ID, cmd Command)

func (*Hub) Run

func (h *Hub) Run(shutdown chan bool)

type ID

type ID string

func IDFromString

func IDFromString(id string) ID

func NewID

func NewID() ID

func (ID) String

func (id ID) String() string

type Packet

type Packet struct {
	To      ID
	Message []byte
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL