wsclient

package
v0.0.0-...-93e01a0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WSSpecificConfPrefix is the 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"
)

Variables

This section is empty.

Functions

func InitPrefix

func InitPrefix(prefix config.KeySet)

InitPrefix ensures the prefix 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 WSAuthConfig

type WSAuthConfig struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

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, prefix config.Prefix, afterConnect WSPostConnectHandler) (WSClient, error)

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.

Jump to

Keyboard shortcuts

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