jsonrpc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 11 Imported by: 0

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 interface{}) error
}

type ClientDecorator

type ClientDecorator func(Client) Client

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

func WithIncrementalID

func WithIncrementalID() ClientDecorator

WithIncrementalID automatically increments JSON-RPC request ID

func WithLog

func WithLog(namespaces ...string) ClientDecorator

func WithRetry

func WithRetry() ClientDecorator

WithRetry automatically retries JSON-RPC calls

func WithTags

func WithTags(component string, namespaces ...string) ClientDecorator

It also attaches the provided component name to the default component tag.

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 interface{}) error

func (ClientFunc) Call

func (f ClientFunc) Call(ctx context.Context, req *Request, res interface{}) 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 testutils is a generated GoMock package.
Package testutils is a generated GoMock package.

Jump to

Keyboard shortcuts

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