wsclient

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// WSSpecificConfPrefix is the named sub-section of the http config options that contains websocket specific config
	WSSpecificConfPrefix = "ws"
	// WSConfigKeyWriteBufferSize is the write buffer size
	WSConfigKeyWriteBufferSize = "ws.writeBufferSize"
	// WSConfigKeyReadBufferSize is the read buffer size
	WSConfigKeyReadBufferSize = "ws.readBufferSize"
	// WSConfigKeyInitialConnectAttempts sets how many times the websocket should attempt to connect on startup, before failing (after initial connection, retry is indefinite)
	WSConfigKeyInitialConnectAttempts = "ws.initialConnectAttempts"
	// WSConfigKeyPath if set will define the path to connect to - allows sharing of the same URL between HTTP and WebSocket connection info
	WSConfigKeyPath = "ws.path"
	// WSConfigHeartbeatInterval is the frequency of ping/pong requests, and also used for the timeout to receive a response to the heartbeat
	WSConfigHeartbeatInterval = "ws.heartbeatInterval"
)

Variables

This section is empty.

Functions

func InitConfig added in v0.1.4

func InitConfig(conf config.KeySet)

InitConfig ensures the config is initialized for HTTP too, as WS and HTTP can share the same tree of configuration (and all the HTTP options apply to the initial upgrade)

func NewTestWSServer

func NewTestWSServer(testReq func(req *http.Request)) (toServer, fromServer chan string, url string, done func())

NewTestWSServer creates a little test server for packages (including wsclient itself) to use in unit tests

Types

type WSClient

type WSClient interface {
	Connect() error
	Receive() <-chan []byte
	URL() string
	SetURL(url string)
	Send(ctx context.Context, message []byte) error
	Close()
}

func New

func New(ctx context.Context, config *WSConfig, beforeConnect WSPreConnectHandler, afterConnect WSPostConnectHandler) (WSClient, error)

type WSConfig

type WSConfig struct {
	HTTPURL                string             `json:"httpUrl,omitempty"`
	WSKeyPath              string             `json:"wsKeyPath,omitempty"`
	ReadBufferSize         int                `json:"readBufferSize,omitempty"`
	WriteBufferSize        int                `json:"writeBufferSize,omitempty"`
	InitialDelay           time.Duration      `json:"initialDelay,omitempty"`
	MaximumDelay           time.Duration      `json:"maximumDelay,omitempty"`
	InitialConnectAttempts int                `json:"initialConnectAttempts,omitempty"`
	AuthUsername           string             `json:"authUsername,omitempty"`
	AuthPassword           string             `json:"authPassword,omitempty"`
	HTTPHeaders            fftypes.JSONObject `json:"headers,omitempty"`
	HeartbeatInterval      time.Duration      `json:"heartbeatInterval,omitempty"`
}

func GenerateConfig added in v0.1.4

func GenerateConfig(conf config.Section) *WSConfig

type WSPostConnectHandler

type WSPostConnectHandler func(ctx context.Context, w WSClient) error

WSPostConnectHandler will be called after every connect/reconnect. Can send data over ws, but must not block listening for data on the ws.

type WSPreConnectHandler

type WSPreConnectHandler func(ctx context.Context) error

WSPreConnectHandler will be called before every connect/reconnect. Any error returned will prevent the websocket from connecting.

Jump to

Keyboard shortcuts

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