jsonrpc2x

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package jsonrpc2x provide helpers for JSON-RPC 2.0 API.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParams = jsonrpc2.NewError(-32602, "invalid params") // Client bug.
	ErrInternal      = jsonrpc2.NewError(-32000, "server error")   // Server bug or I/O issue.
)

Standard errors.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.Mutex
	*jsonrpc2.Client
	// contains filtered or unexported fields
}

Client provides an easier way to use jsonrpc2.Client.

func NewHTTPClient

func NewHTTPClient(url string) *Client

NewHTTPClient wraps jsonrpc2.NewHTTPClient.

func (*Client) Call

func (c *Client) Call(serviceMethod string, args interface{}, reply interface{}) error

Call invokes the named function, waits for it to complete, and returns its error status. It also applies jsonrpc2.WrapError to returned error and automatically handles rpc.ErrShutdown and io.ErrUnexpectedEOF.

type Error

type Error struct {
	Err *jsonrpc2.Error
}

Error wraps JSON-RPC 2.0 "Error object" to match (using errors.Is) any other JSON-RPC 2.0 error with same code.

func NewError

func NewError(code int, message string) *Error

NewError returns an Error with given code and message.

func (*Error) Error

func (e *Error) Error() string

Error returns JSON representation of Error.

func (*Error) Is

func (e *Error) Is(target error) bool

Is reports whether target error's code matches this error's code.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns wrapped error.

type Handler

type Handler func() error

Handler is a JSON-RPC 2.0 method handler.

type Log

type Log = *structlog.Logger

Log is a synonym for convenience.

type Metrics

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

Metrics contains general metrics for JSON-RPC 2.0 methods.

func NewMetrics

func NewMetrics(
	reg *prometheus.Registry,
	service string,
	subsystem string,
	methodsFrom map[string]interface{},
	errsCommon []error,
	errsExtra map[string][]error,
) (
	metric Metrics,
)

NewMetrics registers and returns common JSON-RPC 2.0 metrics used by all services (namespace).

type Middleware

type Middleware func(Handler) Handler

Middleware is a JSON-RPC 2.0 middleware.

func MakeAccessLog

func MakeAccessLog(log Log) Middleware

MakeAccessLog creates middleware which log method call success/failure.

func MakeMetrics

func MakeMetrics(metric Metrics, methodName string) Middleware

MakeMetrics creates middleware which add default metrics.

func MakeRecovery

func MakeRecovery(log Log, metric def.Metrics) Middleware

MakeRecovery creates middleware which handle panics.

func MakeValidateErr

func MakeValidateErr(log Log, strict bool, errsCommon, errsExtra []error) Middleware

MakeValidateErr creates middleware which validates error against documented errors (api.ErrsCommon + api.ErrsExtra[method]).

Use NewError instead of jsonrpc2.NewError to create errors which must match documented errors only by code.

TODO Add new metric to report and extra (metric, methodName) args.

Jump to

Keyboard shortcuts

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