websocket

package
Version: v99.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConnectionNotEstablished is returned by methods that need a connection
	// but no connection is already created.
	ErrConnectionNotEstablished = errors.New("connection has not yet been established")
)

Functions

func HijackIfPossible

func HijackIfPossible(w http.ResponseWriter) (net.Conn, *bufio.ReadWriter, error)

HijackIfPossible calls Hijack() on the given http.ResponseWriter if it implements http.Hijacker interface, which is required for net/http/httputil/reverseproxy to handle connection upgrade/switching protocol. Otherwise returns an error.

Types

type ManagedConnection

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

ManagedConnection represents a websocket connection.

func NewDurableConnection

func NewDurableConnection(target string, messageChan chan []byte, logger *zap.SugaredLogger) *ManagedConnection

NewDurableConnection creates a new websocket connection, that passes incoming messages to the given message channel. It can also send messages to the endpoint it connects to. The connection will continuously be kept alive and reconnected in case of a loss of connectivity.

Note: The given channel needs to be drained after calling `Shutdown` to not cause any deadlocks. If the channel's buffer is likely to be filled, this needs to happen in separate goroutines, i.e.

go func() {conn.Shutdown(); close(messageChan)} go func() {for range messageChan {}}

func NewDurableSendingConnection

func NewDurableSendingConnection(target string, logger *zap.SugaredLogger) *ManagedConnection

NewDurableSendingConnection creates a new websocket connection that can only send messages to the endpoint it connects to. The connection will continuously be kept alive and reconnected in case of a loss of connectivity.

func (*ManagedConnection) Send

func (c *ManagedConnection) Send(msg interface{}) error

Send sends an encodable message over the websocket connection.

func (*ManagedConnection) Shutdown

func (c *ManagedConnection) Shutdown() error

Shutdown closes the websocket connection.

func (*ManagedConnection) Status

func (c *ManagedConnection) Status() error

Status checks the connection status of the webhook.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL