Documentation
¶
Index ¶
- Variables
- func Dial(network, address string) (net.Conn, error)
- func DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func GRPCDialer(ctx context.Context, address string) (net.Conn, error)
- type DialOption
- type Dialer
- type WebSockListener
- type WebSocket
- func (ws *WebSocket) Close() error
- func (ws *WebSocket) LocalAddr() net.Addr
- func (ws *WebSocket) Read(buf []byte) (int, error)
- func (ws *WebSocket) RemoteAddr() net.Addr
- func (*WebSocket) SetDeadline(time.Time) (err error)
- func (*WebSocket) SetReadDeadline(time.Time) error
- func (*WebSocket) SetWriteDeadline(time.Time) error
- func (ws *WebSocket) Write(buf []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWebsocketClosed is returned when operations are performed on a closed Websocket ErrWebsocketClosed = errors.New("WebSocket: Web socket is closed") )
Functions ¶
func Dial ¶
Dial is a standard legacy network dialer that returns a websocket-based connection. See: DialContext for details on the network and address.
func DialContext ¶
DialContext is a standard context-aware network dialer that returns a websocket-based connection. The address is a URL that should be in the form of "ws://host/path..." for unsecured websockets and "wss://host/path..." for secured websockets. If tunnel a TLS based protocol over a "wss://..." websocket you will get TLS twice, once on the websocket using the browsers TLS stack and another using the Go (or other compiled) TLS stack.
func GRPCDialer ¶
GRPCDialer can be used with google.golang.org/grpc.WithContextDialer to call DialContext. The address provided to the calling grpc.Dial should be in the form "passthrough:///"+websocketURL where websocketURL matches the description in DialContext.
Types ¶
type DialOption ¶
type DialOption interface {
// contains filtered or unexported methods
}
DialOption configures how we set up the connection.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) DialOption
WithHTTPClient returns a DialOption that sets the HTTP client for the connection. Has no effect on the browser-based implementation.
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
func NewDialer ¶
func NewDialer(opts ...DialOption) *Dialer
NewDialer allows custom configuration of the websocket dialer.
func (*Dialer) Dial ¶
Dial is a standard legacy network dialer that returns a websocket-based connection. See: DialContext for details on the network and address.
func (*Dialer) DialContext ¶
DialContext is a standard context-aware network dialer that returns a websocket-based connection. The address is a URL that should be in the form of "ws://host/path..." for unsecured websockets and "wss://host/path..." for secured websockets. If tunnel a TLS based protocol over a "wss://..." websocket you will get TLS twice, once on the websocket using the browsers TLS stack and another using the Go (or other compiled) TLS stack.
func (*Dialer) GRPCDialer ¶
GRPCDialer can be used with google.golang.org/grpc.WithContextDialer to call DialContext. The address provided to the calling grpc.Dial should be in the form "passthrough:///"+websocketURL where websocketURL matches the description in DialContext.
type WebSockListener ¶
type WebSockListener struct {
// AcceptOptions are options to be passed to [websocket.Accept].
AcceptOptions *websocket.AcceptOptions
// contains filtered or unexported fields
}
WebSockListener implements net.Listener and provides connections that are incoming websocket connections
func NewWebSocketListener ¶
func NewWebSocketListener(ctx context.Context) *WebSockListener
NewWebSocketListener constructs a new WebSockListener, the provided context is for the lifetime of the listener.
func (*WebSockListener) Accept ¶
func (wsl *WebSockListener) Accept() (net.Conn, error)
Accept fulfills the net.Listener interface and returns net.Conn that are incoming websockets
func (*WebSockListener) Addr ¶
func (wsl *WebSockListener) Addr() net.Addr
RemoteAddr returns a dummy websocket address to satisfy net.Listener
func (*WebSockListener) ServeHTTP ¶
func (wsl *WebSockListener) ServeHTTP(wtr http.ResponseWriter, req *http.Request)
ServeHTTP is a method that is mean to be used as http.HandlerFunc to accept inbound HTTP requests that are websocket connections
type WebSocket ¶
type WebSocket struct {
URL string
// contains filtered or unexported fields
}
WebSocket is a Go struct that wraps the web browser's JavaScript websocket object and provides a net.Conn interface
func New ¶
New returns a new WebSocket using the provided dial context and websocket URL. The URL should be in the form of "ws://host/path..." for unsecured websockets and "wss://host/path..." for secured websockets. If tunnel a TLS based protocol over a "wss://..." websocket you will get TLS twice, once on the websocket using the browsers TLS stack and another using the Go (or other compiled) TLS stack.
func (*WebSocket) LocalAddr ¶
LocalAddr returns a dummy websocket address to satisfy net.Conn, see: wsAddr
func (*WebSocket) RemoteAddr ¶
RemoteAddr returns a dummy websocket address to satisfy net.Conn, see: wsAddr
func (*WebSocket) SetDeadline ¶
SetDeadline implements the SetDeadline method, but is a no-op.
func (*WebSocket) SetReadDeadline ¶
SetReadDeadline implements the SetReadDeadline method but is a no-op.
func (*WebSocket) SetWriteDeadline ¶
SetWriteDeadline implements the SetWriteDeadline method, but is a no-op.