jsonrpc

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package jsonrpc provides a Clarify specific low-level RPC client. Clarify specific details include things like error data format, error codes and API Version headers.

Method names and result formats are not part of this package.

Index

Constants

View Source
const (
	ErrBadRequest  strError = "bad request"
	ErrBadResponse strError = "bad response"
)

Client errors.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorData

type ErrorData struct {
	Trace            string              `json:"trace"`
	Params           map[string][]string `json:"params,omitempty"`
	InvalidResources []InvalidResource   `json:"invalidResources,omitempty"`
	PartialResult    json.RawMessage     `json:"partialResult,omitempty"`
}

ErrorData describes possible error data fields for the Clarify RPC server.

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
	Headers    http.Header
}

HTTPError described a transport-layer error that is returned when the RPC server can not be reached for some reason.

func (HTTPError) Error

func (err HTTPError) Error() string

type HTTPHandler

type HTTPHandler struct {
	Client        http.Client
	URL           string
	RequestLogger func(request Request, trace string, latency time.Duration, err error)
}

HTTPHandler performs RPC requests via HTTP POST against the specified URL.

func (*HTTPHandler) Do

func (c *HTTPHandler) Do(ctx context.Context, req Request, result any) (retErr error)

Do sends the passed in request to the server, and decodes the result or error from the response. Result must be a pointer.

type Handler

type Handler interface {
	Do(ctx context.Context, req Request, result any) error
}

Handler describe the interface for handling arbitrary RPC requests.

type InvalidResource

type InvalidResource struct {
	ID            string              `json:"id,omitempty"`
	Type          string              `json:"type"`
	Message       string              `json:"message"`
	InvalidFields map[string][]string `json:"invalidFields,omitempty"`
}

InvalidResource describes an invalid resource.

type Param

type Param struct {
	Name  string
	Value any
}

Param described a named parameter.

type ParamName

type ParamName string

ParamName can be used to define a parameter name.

func (ParamName) Value

func (name ParamName) Value(v any) Param

type Request

type Request struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	ID      int    `json:"id"`
	Params  any    `json:"params"`

	// Transport layer parameters.
	APIVersion string `json:"-"`
}

Request describe the structure of an RPC Request. The request should be initialized via NewRequest.

func NewRequest

func NewRequest(method string, params ...Param) Request

type ServerError

type ServerError struct {
	Code    int       `json:"code"`
	Message string    `json:"message"`
	Data    ErrorData `json:"data"`
}

ServerError describes the error format returned by the RPC server.

func (ServerError) Error

func (err ServerError) Error() string

Jump to

Keyboard shortcuts

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