jsonrpc

package module
v0.0.0-...-027f451 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: MIT Imports: 3 Imported by: 1

README

jsonrpc

jsonrpc v2.0 client/server implementation for golang

Transport

  • HTTP/HTTPS
  • WS/WSS

User can implement other transport protocol. The sample transport implementation reference link transport package

Usage

see server_test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout    = errors.New("RPC timeout", errors.WithVendor(errVendor), errors.WithCode(-1))
	ErrClose      = errors.New("RPC endpoint closed", errors.WithVendor(errVendor), errors.WithCode(-2))
	ErrTransport  = errors.New("expect transport", errors.WithVendor(errVendor), errors.WithCode(-3))
	ErrDispatcher = errors.New("expect dispatcher", errors.WithVendor(errVendor), errors.WithCode(-4))
	ErrServer     = errors.New("Server type error", errors.WithVendor(errVendor), errors.WithCode(-5))
)

errors

Functions

This section is empty.

Types

type BatchResponses

type BatchResponses []RPCResponse

BatchResponse a list of jsonrpc response objects as a result of a batch request

if you are interested in the response of a specific request use: GetResponseOf(request)

type Client

type Client interface {
	Call(ctx context.Context, method string, args ...interface{}) Reply
	Notification(ctx context.Context, method string, args ...interface{}) error
}

Client jsonrpc Client interface

type ClientTransport

type ClientTransport interface {
	Send(ctx context.Context, buff []byte) error
	Recv() <-chan []byte
}

ClientTransport client underlying transport protocol

type ClientTransportCloser

type ClientTransportCloser interface {
	ClientTransport
	Close() error
}

type RPCError

type RPCError struct {
	Code    RPCErrorCode `json:"code"`
	Message string       `json:"message"`
	Data    interface{}  `json:"data,omitempty"`
}

RPCError represents a jsonrpc error object if an rpc error occurred.

See: http://www.jsonrpc.org/specification#error_object

func (*RPCError) Error

func (e *RPCError) Error() string

type RPCErrorCode

type RPCErrorCode int

RPCErrorCode represents jsonrpc error code

const (
	RPCParseError     RPCErrorCode = -32700
	RPCInvalidRequest RPCErrorCode = -32600
	RPCMethodNotFound RPCErrorCode = -32601
	RPCInvalidParams  RPCErrorCode = -32602
	RPCInternalError  RPCErrorCode = -32603
	RPCServerError    RPCErrorCode = -32000
)

type RPCNotification

type RPCNotification struct {
	JSONRPC string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
}

RPCNotification represents a jsonrpc notification object. A notification object omits the id field since there will be no server response.

See: http://www.jsonrpc.org/specification#notification

type RPCRequest

type RPCRequest struct {
	JSONRPC string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
	ID      *uint       `json:"id,omitempty"`
}

RPCRequest represents a jsonrpc request object.

See: http://www.jsonrpc.org/specification#request_object

type RPCResponse

type RPCResponse struct {
	JSONRPC string      `json:"jsonrpc"`
	Result  interface{} `json:"result,omitempty"`
	Error   *RPCError   `json:"error,omitempty"`
	ID      uint        `json:"id"`
}

RPCResponse represents a jsonrpc response object. If no rpc specific error occurred Error field is nil.

See: http://www.jsonrpc.org/specification#response_object

type Reply

type Reply interface {
	Join(result interface{}) error
	Cancel()
}

type Server

type Server interface {
	Dispatch(context.Context, []byte) ([]byte, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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