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 ¶
type ClientDecorator ¶
ClientDecorator is a function that enable to decorate a JSON-RPC client with additional functionality
func WithExponentialBackOffRetry ¶
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 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
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