astiws

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2020 License: MIT Imports: 6 Imported by: 1

README

Example

Run the 2 following commands at the same time :

$ go run example/manager/main.go -v

$ go run example/client/main.go -v

Documentation

Index

Constants

View Source
const (
	EventNameDisconnect = "astiws.disconnect"
	PingPeriod          = (pingWait * 9) / 10
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyMessage

type BodyMessage struct {
	EventName string      `json:"event_name"`
	Payload   interface{} `json:"payload"`
}

type BodyMessageRead

type BodyMessageRead struct {
	BodyMessage
	Payload json.RawMessage `json:"payload"`
}

represents the body of a message for read purposes Indeed when reading the body, we need the payload to be a json.RawMessage

type Client

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

func NewClient

func NewClient(c ClientConfiguration, options ...ClientOption) *Client

func (*Client) AddListener

func (c *Client) AddListener(eventName string, f ListenerFunc)

func (*Client) Close

func (c *Client) Close() (err error)

func (*Client) DelListener

func (c *Client) DelListener(eventName string)

func (*Client) Dial

func (c *Client) Dial(addr string) error

func (*Client) DialWithHeaders

func (c *Client) DialWithHeaders(addr string, h http.Header) error

func (*Client) HandlePing

func (c *Client) HandlePing() error

func (*Client) Read

func (c *Client) Read() (err error)

func (*Client) SetListener

func (c *Client) SetListener(eventName string, f ListenerFunc)

func (*Client) Write

func (c *Client) Write(eventName string, payload interface{}) (err error)

type ClientAdapter

type ClientAdapter func(c *Client)

type ClientConfiguration

type ClientConfiguration struct {
	MaxMessageSize int `toml:"max_message_size"`
}

type ClientOption

type ClientOption func(client *Client)

func WithErrHandler

func WithErrHandler(errHandler func(err error)) ClientOption

type ListenerFunc

type ListenerFunc func(c *Client, eventName string, payload json.RawMessage) error

type Manager

type Manager struct {
	Upgrader websocket.Upgrader
	// contains filtered or unexported fields
}

func NewManager

func NewManager(c ManagerConfiguration) *Manager

func (*Manager) AutoRegisterClient

func (m *Manager) AutoRegisterClient(c *Client)

func (*Manager) Client

func (m *Manager) Client(k interface{}) (c *Client, ok bool)

func (*Manager) Clients

func (m *Manager) Clients(fn func(k interface{}, c *Client) error)

executes a function on every client. It stops if an error is returned.

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) CountClients

func (m *Manager) CountClients() int

func (*Manager) Loop

func (m *Manager) Loop(fn func(k interface{}, c *Client))

loops in clients and execute a function for each of them

func (*Manager) RegisterClient

func (m *Manager) RegisterClient(k interface{}, c *Client)

func (*Manager) ServeHTTP

func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request, adapter ClientAdapter) (err error)

handles an HTTP request and returns an error unlike an http.Handler We don't want to register the client yet, since we may want to index the map of clients with an information we don't have yet

func (*Manager) UnregisterClient

func (m *Manager) UnregisterClient(k interface{})

astiws.disconnected event is a good place to call this function

type ManagerConfiguration

type ManagerConfiguration struct {
	MaxMessageSize int `toml:"max_message_size"`
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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