wsclient

package
v6.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Close() error
	SetReadDeadline(time.Time) error
	ReadMessage() (int, []byte, error)
	WriteMessage(int, []byte) error
}

Conn is the interface for a *websocket.Conn as used in this wrapper package

type Dialer

type Dialer interface {
	Dial(string, http.Header) (Conn, *http.Response, error)
}

Dialer is the interface for a *websocket.Dialer as used in this wrapper package

func WrapDialer

func WrapDialer(d *websocket.Dialer) Dialer

WrapDialer will wrap a *websocket.Dialer so it conforms to this package's interface

type MessageHandler

type MessageHandler interface {
	HandleRequest(WSMessage, chan<- WSMessage)
}

MessageHandler is the api of an object that has a HandleRequest MessageHandlerFunc method

func NewMessageHandler

func NewMessageHandler(h MessageHandlerFunc) MessageHandler

NewMessageHandler creates a MessageHandler from the given MessageHandlerFunc

type MessageHandlerFunc

type MessageHandlerFunc func(m WSMessage, resp chan<- WSMessage)

MessageHandlerFunc is the api of a handler that processes a WSMessage and sends a response back over the response channe;

type MessageType

type MessageType int

MessageType represents the type of data being sent or received over a websocket connection

const (
	Text   MessageType = 1
	Binary             = 2
)

Websocket Message types

func (MessageType) String

func (t MessageType) String() string

type Options

type Options struct {
	GatewayURL            string
	MaxConcurrentHandlers int
}

Options enables setting up a WSClient with the desired connection settings

type WSClient

type WSClient interface {
	SetGateway(string)
	SetHandler(MessageHandler)
	Connect(string) error
	Close()
	HandleRequests(context.Context) error
	SendMessage(msg WSMessage)
}

WSClient is the api for a client that maintains an active websocket connection and hands off messages to be processed.

func NewWSClient

func NewWSClient(deps dependencies, options Options) WSClient

NewWSClient creates a new WSClient

type WSMessage

type WSMessage struct {
	Ctx             context.Context
	MessageType     MessageType
	MessageContents []byte
}

WSMessage is a struct that wraps a message received or to be sent over a websocket connection

func (WSMessage) String

func (m WSMessage) String() string

Jump to

Keyboard shortcuts

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