wrpc

package
v0.0.0-...-2374aa5 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDialer = &Dialer{
	Dialer: websocket.Dialer{
		Proxy:            http.ProxyFromEnvironment,
		HandshakeTimeout: defaultHandshakeTimeout,
	},
}

DefaultDialer is a wRPC Dialer with all fields set to the default values.

Functions

This section is empty.

Types

type Conn

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

Conn is a wRPC connection. A wRPC connection consists of an HTTP Websocket connection and some additional state around it.

func NewConn

func NewConn(conn *websocket.Conn) *Conn

NewConn creates a wRCP connection using a websocket connection. It is assumed that the websocket connection has already been upgraded to wRPC during the handshake.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the underlying connection. An attempt is made to close the connection gracefully and if that fails, then it is closed forcefully.

func (*Conn) DoRPC

func (c *Conn) DoRPC(ctx context.Context, req Request) (Response, error)

DoRPC invokes a request and returns the response. The returned error signals a protocol error and not an application-layer error.

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

type Dialer

type Dialer struct {
	websocket.Dialer
}

func (*Dialer) Dial

func (d *Dialer) Dial(
	ctx context.Context,
	urlStr string,
	requestHeader http.Header,
) (*Conn, *http.Response, error)

Dial creates a new wRPC connection by calling DialContext with a background context.

type Handler

type Handler func(ctx context.Context, peer *Peer, decoder func(interface{}) error) (
	interface{}, error)

Handler is the handler for a specific wRPC call. decoder function is used to unmarshal the request. The handler must return the response of the interface and any error. Error must not be used to signal application-level failures.

type ID

type ID uint32

type Peer

type Peer struct {
	ErrLogger func(error)
	// ClosedCallbackFunc if set, called after closing the connection.
	ClosedCallbackFunc func(*Peer)
	// contains filtered or unexported fields
}

Peer represents a wRPC peer. A peer is capable of invoking and responding to RPCs.

func (*Peer) AddConn

func (p *Peer) AddConn(conn *Conn)

AddConn adds a connection to peer and starts listenting for requests on the connection.

func (*Peer) Clone

func (p *Peer) Clone() *Peer

Clone returns a new Peer with the same registry and logger, ready for either AddConn() or Upgrade()

func (*Peer) Close

func (p *Peer) Close() error

func (*Peer) DoRequest

func (p *Peer) DoRequest(ctx context.Context, req Request, output proto.Message) error

DoRequest sends a prepared request to the peer.

func (*Peer) Register

func (p *Peer) Register(s Service) error

Register registers a Service for communication.

func (*Peer) RemoteAddr

func (p *Peer) RemoteAddr() net.Addr

func (*Peer) Upgrade

func (p *Peer) Upgrade(w http.ResponseWriter, r *http.Request) error

Upgrade upgrades an HTTP connection to wRPC connection and starts tracking the connection.

func (*Peer) VerifyRPC

func (p *Peer) VerifyRPC(svcID, rpcID ID) error

VerifyRPC returns an error if the svcID/rpcID pair doesn't correspond to a registered RPC.

type RPC

type RPC interface {
	// Handler returns the handler that will be invoked to complete an RPC.
	Handler() Handler
}

RPC represent a wRPC RPC defined for a Service.

type RPCImpl

type RPCImpl struct {
	HandlerFunc Handler
}

func (RPCImpl) Handler

func (r RPCImpl) Handler() Handler

type Request

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

func CreateRequest

func CreateRequest(svcID, rpcID ID, input interface{}) (Request, error)

CreateRequest marshals and wraps a generic input as the payload in a new request

type Response

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

type Service

type Service interface {
	// ID returns the svc_id for a wRPC service.
	ID() ID
	// RPC returns a handler for a rpc_id.
	// Nil handler must be returned if the rpc_id is invalid.
	RPC(ID) RPC
}

Service represents a wRPC service. All functions are thread-safe.

type ServiceImpl

type ServiceImpl struct {
	SvcID ID
	RPCs  map[ID]RPC
}

ServiceImpl implements Service

type Upgrader

type Upgrader struct{}

func (*Upgrader) Upgrade

func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request) (*Conn, error)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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