gocket

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientClosed     = errors.New("client closed")
	ErrAlreadyConnected = errors.New("client already connected")
)

Functions

func IsNormalClose

func IsNormalClose(err error) bool

Types

type AcceptOptions

type AcceptOptions = websocket.AcceptOptions

type Client

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

func NewClient

func NewClient(opts ...ClientOption) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Dial

func (c *Client) Dial(ctx context.Context, url string) error

nolint:bodyclose

func (*Client) Emit

func (c *Client) Emit(ctx context.Context, event string, data []byte) error

func (*Client) EmitWithAck

func (c *Client) EmitWithAck(ctx context.Context, event string, data []byte) ([]byte, error)

func (*Client) On

func (c *Client) On(event string, handler Handler) *Client

func (*Client) OnConnect

func (c *Client) OnConnect(handler ConnectHandler) *Client

func (*Client) OnDisconnect

func (c *Client) OnDisconnect(handler DisconnectHandler) *Client

func (*Client) OnError

func (c *Client) OnError(handler ErrorHandler) *Client

func (*Client) OnUnknownEvent

func (c *Client) OnUnknownEvent(handler Handler) *Client

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

type ClientOption

type ClientOption func(*clientOptions)

func WithClientDialOptions

func WithClientDialOptions(opts *DialOptions) ClientOption

func WithClientReadLimit

func WithClientReadLimit(limit int64) ClientOption

type Conn

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

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Data

func (c *Conn) Data() *ds.SafeMap[string, any]

func (*Conn) Emit

func (c *Conn) Emit(ctx context.Context, event string, data []byte) error

func (*Conn) EmitWithAck

func (c *Conn) EmitWithAck(ctx context.Context, event string, data []byte) ([]byte, error)

func (*Conn) HttpRequest

func (c *Conn) HttpRequest() *http.Request

func (*Conn) Id

func (c *Conn) Id() string

func (*Conn) Ping

func (c *Conn) Ping(ctx context.Context) error

type ConnectHandler

type ConnectHandler func(conn *Conn)

type DialOptions

type DialOptions = websocket.DialOptions

type DisconnectHandler

type DisconnectHandler func(conn *Conn, err error)

type ErrorHandler

type ErrorHandler func(conn *Conn, err error)

type Handler

type Handler interface {
	Handle(ctx context.Context, conn *Conn, msg Message) []byte
}

type HandlerFunc

type HandlerFunc func(ctx context.Context, conn *Conn, msg Message) []byte

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(ctx context.Context, conn *Conn, msg Message) []byte

type Message

type Message struct {
	Event string
	Data  json.RawMessage `json:",omitempty"`
	AckId uint64          `json:",omitempty"`
}

func (*Message) Encode

func (m *Message) Encode(buff *bytes.Buffer)

func (*Message) IsAckRequired

func (m *Message) IsAckRequired() bool

func (*Message) Marshal

func (m *Message) Marshal() []byte

func (*Message) Unmarshal

func (m *Message) Unmarshal(data []byte) error

nolint:mnd

type Rooms

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

func (*Rooms) AllConns

func (s *Rooms) AllConns() []*Conn

func (*Rooms) Clear

func (s *Rooms) Clear(rooms ...string)

func (*Rooms) Get

func (s *Rooms) Get(connId string) (*Conn, bool)

func (*Rooms) Join

func (r *Rooms) Join(conn *Conn, rooms ...string)

func (*Rooms) Leave

func (r *Rooms) Leave(connId string, rooms ...string)

func (*Rooms) Len

func (s *Rooms) Len(room string) int

func (*Rooms) Rooms

func (s *Rooms) Rooms() []string

func (*Rooms) ToBroadcast

func (s *Rooms) ToBroadcast(rooms ...string) []*Conn

type Server

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

func NewServer

func NewServer(opts ...ServerOption) *Server

func (*Server) On

func (s *Server) On(event string, handler Handler) *Server

func (*Server) OnConnect

func (s *Server) OnConnect(handler ConnectHandler) *Server

func (*Server) OnDisconnect

func (s *Server) OnDisconnect(handler DisconnectHandler) *Server

func (*Server) OnError

func (s *Server) OnError(handler ErrorHandler) *Server

func (*Server) OnUnknownEvent

func (s *Server) OnUnknownEvent(handler Handler) *Server

func (*Server) Rooms

func (s *Server) Rooms() *Rooms

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Shutdown

func (s *Server) Shutdown()

type ServerOption

type ServerOption func(*serverOptions)

func WithServerAcceptOptions

func WithServerAcceptOptions(opts *AcceptOptions) ServerOption

func WithServerReadLimit

func WithServerReadLimit(limit int64) ServerOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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