client

package
v0.0.0-...-3df06e7 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents websocket client

func (*Client) Close

func (c *Client) Close(code int)

func (*Client) ID

func (c *Client) ID() uint64

ID returns a client id

func (*Client) IsClosed

func (c *Client) IsClosed() bool

IsClosed returns true if the client was closed

func (*Client) OnClose

func (c *Client) OnClose(h func())

OnClose sets a close handler

func (*Client) OnSubscribe

func (c *Client) OnSubscribe(h func(params []string))

OnSubscribe sets a subscribing handler

func (*Client) OnUnsubscribe

func (c *Client) OnUnsubscribe(h func(params []string))

OnSubscribe sets a unsubscribing handler

func (*Client) Send

func (c *Client) Send(msg []byte)

Send sends a message to the peer

type Config

type Config struct {
	WriteWaitTimeout   time.Duration
	PongWaitTimeout    time.Duration
	PingInterval       time.Duration
	MaxReadMessageSize int64
	SendBufferSize     int
}

Config represents a factory configuration

type Factory

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

Factory is a factory for creating websocket clients

func NewFactory

func NewFactory(c Config) (*Factory, error)

NewFactory creates a client factory

func (*Factory) New

func (cf *Factory) New(conn GorillaConnection) *Client

type GorillaConnection

type GorillaConnection interface {
	SetReadDeadline(t time.Time) error
	SetReadLimit(limit int64)
	SetPongHandler(h func(appData string) error)
	ReadMessage() (messageType int, p []byte, err error)
	SetWriteDeadline(t time.Time) error
	WriteMessage(messageType int, data []byte) error
	Close() error
}

GorillaConnection represents a contract for gorilla websocket connection

type Request

type Request struct {
	ID     uint64   `json:"id"`
	Method string   `json:"method"`
	Params []string `json:"params"`
}

Request represents a websocket request payload

type Response

type Response struct {
	ID     uint64         `json:"id,omitempty"`
	Error  *ResponseError `json:"error,omitempty"`
	Result interface{}    `json:"result,omitempty"`
}

Response represents a websocket response payload

type ResponseError

type ResponseError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ResponseError is a response error

Jump to

Keyboard shortcuts

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