rpc

package
v0.0.0-...-da19eeb Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShutdown    = errors.New("connection is shut down")
	ErrCallTimeout = errors.New("rpc request timed out")
)
View Source
var ErrNotConnected = errors.New("websocket is not connected")

ErrNotConnected is returned when the application read/writes a message and the connection is closed

Functions

This section is empty.

Types

type ErrorFunc

type ErrorFunc func(error)

type NotifyFunc

type NotifyFunc func(method string, params json.RawMessage)

type RPCCall

type RPCCall struct {
	Method  string
	Request rpcRequest
	Result  json.RawMessage
	Done    chan error
}

type RPCClient

type RPCClient interface {
	CallAPI(method string, args ...interface{}) (interface{}, error)
	Close() error
	Connect() error
}

func NewRPCClient

func NewRPCClient(rpcEndpointURL string) RPCClient

NewRPCClient creates a RPC Client

type RecConn

type RecConn struct {
	// RecIntvlMin specifies the initial reconnecting interval,
	// default to 2 seconds
	RecIntvlMin time.Duration
	// RecIntvlMax specifies the maximum reconnecting interval,
	// default to 30 seconds
	RecIntvlMax time.Duration
	// RecIntvlFactor specifies the rate of increase of the reconnection
	// interval, default to 1.5
	RecIntvlFactor float64
	// HandshakeTimeout specifies the duration for the handshake to complete,
	// default to 2 seconds
	HandshakeTimeout time.Duration

	*websocket.Conn
	// contains filtered or unexported fields
}

The RecConn type represents a Reconnecting WebSocket connection.

func NewRecConn

func NewRecConn() *RecConn

func (*RecConn) Close

func (rc *RecConn) Close()

Close closes the underlying network connection without sending or waiting for a close frame.

func (*RecConn) Dial

func (rc *RecConn) Dial(urlStr string) error

Dial creates a new client connection. The URL url specifies the host and request URI. Use requestHeader to specify the origin (Origin), subprotocols (Sec-WebSocket-Protocol) and cookies (Cookie). Use GetHTTPResponse() method for the response.Header to get the selected subprotocol (Sec-WebSocket-Protocol) and cookies (Set-Cookie). func (rc *RecConn) Dial(urlStr string, reqHeader http.Header) {

func (*RecConn) GetDialError

func (rc *RecConn) GetDialError() error

GetDialError returns the last dialer error. nil on successful connection.

func (*RecConn) GetHTTPResponse

func (rc *RecConn) GetHTTPResponse() *http.Response

GetHTTPResponse returns the http response from the handshake. Useful when WebSocket handshake fails, so that callers can handle redirects, authentication, etc.

func (*RecConn) IsConnected

func (rc *RecConn) IsConnected() bool

IsConnected returns the WebSocket connection state

func (*RecConn) ReadJSON

func (rc *RecConn) ReadJSON(v interface{}) error

ReadJSON reads the JSON encoding from connection to v

func (*RecConn) ReadMessage

func (rc *RecConn) ReadMessage() (messageType int, message []byte, err error)

ReadMessage is a helper method for getting a reader using NextReader and reading from that reader to a buffer.

If the connection is closed ErrNotConnected is returned

func (*RecConn) RegisterCallback

func (rc *RecConn) RegisterCallback(f func(event string, data []byte))

func (*RecConn) WriteJSON

func (rc *RecConn) WriteJSON(v interface{}) error

WriteJSON writes the JSON encoding of v to the connection.

See the documentation for encoding/json Marshal for details about the conversion of Go values to JSON.

If the connection is closed ErrNotConnected is returned

func (*RecConn) WriteMessage

func (rc *RecConn) WriteMessage(messageType int, data []byte) error

WriteMessage is a helper method for getting a writer using NextWriter, writing the message and closing the writer.

If the connection is closed ErrNotConnected is returned

type WebsocketClient

type WebsocketClient interface {
	OnError(fn ErrorFunc)
	OnNotify(fn NotifyFunc)
	Call(method string, result interface{}, args ...interface{}) error
	Close() error
	Connect() error
	RegisterCallback(fn func(event string, data []byte))
}

func NewWebsocketClient

func NewWebsocketClient(endpointURL string) WebsocketClient

Jump to

Keyboard shortcuts

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