jsonrpc

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ParserError    = RPCError{Code: -32700, Message: "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."}
	InvalidRequest = RPCError{Code: -32600, Message: "The JSON sent is not a valid Request object."}
	MethodNotFound = RPCError{Code: -32601, Message: "The method does not exist / is not available."}
	InvalidParams  = RPCError{Code: -32602, Message: "Invalid method parameter(s)."}
	InternalError  = RPCError{Code: -32603, Message: "Internal JSON-RPC error."}
	ServerError    = RPCError{Code: -32000, Message: "Reserved for implementation-defined server-errors."}
)

Functions

func ConnClosed

func ConnClosed(conn *net.Conn) bool

Types

type Client

type Client interface {
	Address() string
	Call(request *Request) (*Response, error)
	CallContext(ctx context.Context, request *Request) (*Response, error)
	CallBatch(requests ...*Request) ([]*Response, error)
	CallBatchContext(ctx context.Context, requests ...*Request) ([]*Response, error)
}

type Conn

type Conn net.Conn

type ConnectionPool

type ConnectionPool struct {
	New func() (*net.Conn, error)
	// contains filtered or unexported fields
}

func NewConnPool

func NewConnPool(newFunc func() (*net.Conn, error)) *ConnectionPool

func (*ConnectionPool) Get

func (p *ConnectionPool) Get() *net.Conn

func (*ConnectionPool) GetOrNew

func (p *ConnectionPool) GetOrNew() (*net.Conn, error)

func (*ConnectionPool) Init

func (p *ConnectionPool) Init(n int) (int, []error)

creat N connection in pool

func (*ConnectionPool) Len

func (p *ConnectionPool) Len() int

func (*ConnectionPool) Put

func (p *ConnectionPool) Put(conn *net.Conn)

type RPCError

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

func (RPCError) Error

func (e RPCError) Error() string

func (RPCError) Is

func (e RPCError) Is(err error) bool

for errors.Is

func (RPCError) IsRpcError

func (e RPCError) IsRpcError(err RPCError) bool

type Request

type Request struct {
	Method string      `json:"method"`
	Params interface{} `json:"params"`
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(method string, params interface{}) *Request

func (Request) MarshalJSON

func (r Request) MarshalJSON() ([]byte, error)

type Response

type Response struct {
	Version string          `json:"jsonrpc,omitempty"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
	Id      int64           `json:"id,omitempty"`
}

func (*Response) Err

func (r *Response) Err() error

used for error assertion

func (*Response) GetBigFloat

func (r *Response) GetBigFloat() (big.Float, error)

func (*Response) GetFloat64

func (r *Response) GetFloat64() (float64, error)

func (*Response) GetInt64

func (r *Response) GetInt64() (int64, error)

func (*Response) GetNumber

func (r *Response) GetNumber() (json.Number, error)

func (*Response) GetObject

func (r *Response) GetObject(obj interface{}) error

func (*Response) GetString

func (r *Response) GetString() (string, error)

func (*Response) RawResult

func (r *Response) RawResult() []byte

type TCPClient

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

func NewTCPClient

func NewTCPClient(addr string) *TCPClient

func (TCPClient) Address

func (c TCPClient) Address() string

func (*TCPClient) Call

func (c *TCPClient) Call(request *Request) (*Response, error)

func (*TCPClient) CallBatch

func (c *TCPClient) CallBatch(requests ...*Request) ([]*Response, error)

func (*TCPClient) CallBatchContext

func (c *TCPClient) CallBatchContext(ctx context.Context, requests ...*Request) ([]*Response, error)

func (*TCPClient) CallContext

func (c *TCPClient) CallContext(ctx context.Context, request *Request) (*Response, error)

Jump to

Keyboard shortcuts

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