jsonrpc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603
	// -32000 to -32599	Server error, Reserved for implementation-defined server-errors.
	CodeServerError = -32000
)

refer to JSON-RPC 2.0. https://www.jsonrpc.org/specification

View Source
const (
	MIMEApplicationJSON            = "application/json"
	MIMEApplicationJSONCharsetUTF8 = "application/json; charset=utf-8"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error added in v0.1.0

type Error = erring.Error

Error is a JSON-RPC error.

type Handler added in v0.1.0

type Handler interface {
	// ServeRPC handles a JSON-RPC request.
	ServeRPC(context.Context, *Request) *Response
}

type Request added in v0.1.0

type Request struct {
	Version string          `json:"jsonrpc"`
	ID      string          `json:"id"` // only support string id
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request represents a JSON-RPC 2.0 request.

func (*Request) DecodeParams added in v0.1.0

func (req *Request) DecodeParams(params any) error

DecodeParams decodes the request parameters into the given value.

func (*Request) Error added in v0.1.0

func (req *Request) Error(err error) *Response

Error returns a response from the request with the given error.

func (*Request) InvalidMethod added in v0.1.0

func (req *Request) InvalidMethod() *Response

InvalidMethod returns a invalid method response from the request.

func (*Request) InvalidParams added in v0.1.0

func (req *Request) InvalidParams(msg string) *Response

InvalidParams returns a invalid params response from the request with the given message.

func (*Request) ReadFrom added in v0.1.0

func (req *Request) ReadFrom(r io.Reader) (int64, error)

ReadFrom decodes the request from the given reader. ReadFrom implements io.ReaderFrom interface.

func (*Request) Result added in v0.1.0

func (req *Request) Result(result any) *Response

Result returns a response from the request with the given result.

func (*Request) String added in v0.1.0

func (req *Request) String() string

String returns the string representation of the request.

type Response added in v0.1.0

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

Response represents a JSON-RPC response.

func (*Response) DecodeResult added in v0.1.0

func (res *Response) DecodeResult(result any) error

DecodeResult decodes the result into the given value.

func (*Response) ReadFrom added in v0.1.0

func (res *Response) ReadFrom(r io.Reader) (int64, error)

ReadFrom decodes the JSON-RPC response from the given reader. ReadFrom implements io.ReaderFrom interface.

func (*Response) String added in v0.1.0

func (res *Response) String() string

String returns the string representation of the response.

Jump to

Keyboard shortcuts

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