jsonrpc

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: May 20, 2025 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {

	// res MUST be a pointer so JSON-RPC result can be unmarshalled into res. You
	// can also pass nil, in which case the result is ignored.
	Call(ctx context.Context, req *Request, res any) error
}

func WithMetrics added in v0.3.0

func WithMetrics(client Client) Client

func WithTags

func WithTags(client Client) Client

WithTags is a decorator that attaches following JSON-RPC specific tags to the Call context . - req.method: JSON-RPC method - req.version: JSON-RPC version - req.params: JSON-RPC params - req.id: JSON-RPC id

It also makes the client Taggable

type ClientDecorator

type ClientDecorator func(Client) Client

ClientDecorator is a function that enable to decorate a JSON-RPC client with additional functionality

func WithExponentialBackOffRetry added in v0.3.3

func WithExponentialBackOffRetry(opts ...backoff.ExponentialBackOffOpts) ClientDecorator

WithExponentialBackOffRetry automatically retries JSON-RPC calls

func WithIncrementalID

func WithIncrementalID() ClientDecorator

WithIncrementalID automatically increments JSON-RPC request ID

func WithLog

func WithLog(namespaces ...string) ClientDecorator

func WithTimeout

func WithTimeout(d time.Duration) ClientDecorator

WithTimeout automatically sets a timeout for JSON-RPC calls

func WithVersion

func WithVersion(v string) ClientDecorator

WithVersion automatically set JSON-RPC request version

type ClientFunc

type ClientFunc func(ctx context.Context, req *Request, res any) error

func (ClientFunc) Call

func (f ClientFunc) Call(ctx context.Context, req *Request, res any) error

type ErrorMsg

type ErrorMsg struct {
	Code    int              `json:"code"`
	Message string           `json:"message"`
	Data    *json.RawMessage `json:"data,omitempty"`
}

ErrorMsg is a struct allowing to encode/decode an error in a JSON-RPC response body

func (ErrorMsg) Error

func (err ErrorMsg) Error() string

type Request

type Request struct {
	Version string
	Method  string
	ID      interface{}
	Params  interface{}
}

Request allows to manipulate a JSON-RPC request

func (*Request) MarshalJSON

func (msg *Request) MarshalJSON() ([]byte, error)

MarshalJSON

type RequestMsg

type RequestMsg struct {
	Version string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
	ID      interface{}     `json:"id,omitempty"`
}

RequestMsg is a struct allowing to encode/decode a JSON-RPC request body

type ResponseMsg

type ResponseMsg struct {
	Version string          `json:"jsonrpc"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   json.RawMessage `json:"error,omitempty"`
	ID      interface{}     `json:"id,omitempty"`
}

ResponseMsg is a struct allowing to encode/decode a JSON-RPC response body

func DecodeResponseMsg

func DecodeResponseMsg(r io.Reader) (*ResponseMsg, error)

DecodeResponseMsg decodes a JSON-RPC response message from an io.Reader

func (*ResponseMsg) Unmarshal

func (msg *ResponseMsg) Unmarshal(res interface{}) error

Unmarshal unmarshals a JSON-RPC response result into a given interface If the response contains an error, it will be unmarshaled into an ErrorMsg and returned

Directories

Path Synopsis
Package jsonrpcmock is a generated GoMock package.
Package jsonrpcmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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