Documentation ¶
Index ¶
- Variables
- type Conn
- type Dialer
- type Handler
- type ID
- type Peer
- func (p *Peer) AddConn(conn *Conn)
- func (p *Peer) Clone() *Peer
- func (p *Peer) Close() error
- func (p *Peer) DoRequest(ctx context.Context, req Request, output proto.Message) error
- func (p *Peer) Register(s Service) error
- func (p *Peer) RemoteAddr() net.Addr
- func (p *Peer) Upgrade(w http.ResponseWriter, r *http.Request) error
- func (p *Peer) VerifyRPC(svcID, rpcID ID) error
- type RPC
- type RPCImpl
- type Request
- type Response
- type Service
- type ServiceImpl
- type Upgrader
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
DoRPC invokes a request and returns the response. The returned error signals a protocol error and not an application-layer error.
func (*Conn) RemoteAddr ¶
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 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 ¶
AddConn adds a connection to peer and starts listenting for requests on the connection.
func (*Peer) Clone ¶
Clone returns a new Peer with the same registry and logger, ready for either AddConn() or Upgrade()
func (*Peer) RemoteAddr ¶
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 Request ¶
type Request struct {
// contains filtered or unexported fields
}
func CreateRequest ¶
CreateRequest marshals and wraps a generic input as the payload in a new request
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 ¶
ServiceImpl implements Service