Documentation ¶
Index ¶
- Constants
- func GenerateTLSCertficates(t *testing.T) (publicKeyFile *os.File, privateKeyFile *os.File)
- func InitConfig(conf config.Section)
- func NewTestTLSWSServer(testReq func(req *http.Request), publicKeyFile *os.File, ...) (toServer, fromServer chan string, url string, done func(), err error)
- func NewTestWSServer(testReq func(req *http.Request)) (toServer, fromServer chan string, url string, done func())
- type WSClient
- type WSConfig
- type WSPayload
- type WSPostConnectHandler
- type WSPreConnectHandler
Constants ¶
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" // WSConfigURL if set will be a completely separate URL for WebSockets (must be a ws: or wss: scheme) WSConfigURL = "ws.url" // WSConfigKeyHeartbeatInterval is the frequency of ping/pong requests, and also used for the timeout to receive a response to the heartbeat WSConfigKeyHeartbeatInterval = "ws.heartbeatInterval" // WSConnectionTimeout is the amount of time to wait while attempting to establish a connection (or automatic reconnection) WSConfigKeyConnectionTimeout = "ws.connectionTimeout" )
Variables ¶
This section is empty.
Functions ¶
func GenerateTLSCertficates ¶ added in v1.2.10
GenerateTLSCertificates creates a key pair for server and client auth
func InitConfig ¶ added in v0.1.4
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 NewTestTLSWSServer ¶ added in v1.2.10
func NewTestTLSWSServer(testReq func(req *http.Request), publicKeyFile *os.File, privateKeyFile *os.File) (toServer, fromServer chan string, url string, done func(), err error)
NewTestTLSWSServer creates a little test server for packages (including wsclient itself) to use in unit tests and secured with mTLS by passing in a key pair
Types ¶
type WSClient ¶
type WSClient interface { Connect() error Receive() <-chan []byte ReceiveExt() <-chan *WSPayload URL() string SetURL(url string) SetHeader(header, value 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"` WebSocketURL string `json:"wsUrl,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"` DisableReconnect bool `json:"disableReconnect"` AuthUsername string `json:"authUsername,omitempty"` AuthPassword string `json:"authPassword,omitempty"` HTTPHeaders fftypes.JSONObject `json:"headers,omitempty"` HeartbeatInterval time.Duration `json:"heartbeatInterval,omitempty"` TLSClientConfig *tls.Config `json:"tlsClientConfig,omitempty"` ConnectionTimeout time.Duration `json:"connectionTimeout,omitempty"` // This one cannot be set in JSON - must be configured on the code interface ReceiveExt bool }
type WSPayload ¶ added in v1.2.11
type WSPayload struct { MessageType int Reader io.Reader // contains filtered or unexported fields }
WSPayload allows API consumers of this package to stream data, and inspect the message type, rather than just being passed the bytes directly.
type WSPostConnectHandler ¶
WSPostConnectHandler will be called after every connect/reconnect. Can send data over ws, but must not block listening for data on the ws.