jsonrpc

package module
v0.0.0-...-39bc726 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

go-jsonrpc

Build Coverage Status License

Status: EXPERIMENTAL

TBD

Documentation

GoDoc

Full go doc style documentation for the project can be viewed online without installing this package by using the excellent GoDoc site here: http://godoc.org/github.com/41north/go-jsonrpc

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/41north/go-jsonrpc

Installation

$ go get -u github.com/41north/go-jsonrpc

Add this import line to the file you're working in:

import "github.com/41north/go-jsonrpc"

Quick Start

There are more examples available in the go doc.

License

Go-async is licensed under the Apache 2.0 License

Contact

If you want to get in touch drop us an email at hello@41north.dev

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRequest = Error{
		Code:    -32600,
		Message: "invalid request",
	}
	ErrMethodNotFound = Error{
		Code:    -32601,
		Message: "method not found",
	}
	ErrInvalidParams = Error{
		Code:    -32602,
		Message: "invalid params",
	}
	ErrInternal = Error{
		Code:    -32603,
		Message: "internal error",
	}
	ErrParse = Error{
		Code:    -32700,
		Message: "parse error",
	}
)
View Source
var (
	ErrClosed = errors.ConstError("connection has been closed")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Connect() error

	Send(req Request, resp *Response) error
	SendContext(ctx context.Context, req Request, resp *Response) error
	SendAsync(req Request) ResponseFuture

	SetCloseHandler(handler CloseHandler)
	SetRequestHandler(handler RequestHandler)

	Close() error
}

func NewClient

func NewClient(dialer Dialer) Client

type CloseHandler

type CloseHandler = func(err error)

type Connection

type Connection interface {
	Write(data []byte) error
	Read() ([]byte, error)
	Close() error
}

type Dialer

type Dialer interface {
	Dial() (Connection, error)
	DialContext(ctx context.Context) (Connection, error)
}

type Error

type Error struct {
	Code    int32           `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

func (Error) Error

func (e Error) Error() string

Error renders e to a human-readable string for the error interface.

type IdGenerator

type IdGenerator = func() string

type Request

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

func NewRequest

func NewRequest(method string, params any, options ...RequestOption) (*Request, error)

func (*Request) EnsureId

func (r *Request) EnsureId(gen IdGenerator) error

func (*Request) UnmarshalId

func (r *Request) UnmarshalId(id any) error

func (*Request) UnmarshalParams

func (r *Request) UnmarshalParams(payload any) error

type RequestHandler

type RequestHandler = func(req Request)

type RequestOption

type RequestOption = func(opts *RequestOptions) error

func RequestNumericId

func RequestNumericId(id int) RequestOption

func RequestStringId

func RequestStringId(id string) RequestOption

func RequestVersion

func RequestVersion(version string) RequestOption

type RequestOptions

type RequestOptions struct {
	Version string
	Id      json.RawMessage
}

func DefaultRequestOptions

func DefaultRequestOptions() RequestOptions

type Response

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

func NewResponse

func NewResponse(result any, options ...ResponseOption) (*Response, error)

func NewResponseError

func NewResponseError(error Error, options ...ResponseOption) (*Response, error)

func (*Response) UnmarshalId

func (r *Response) UnmarshalId(payload any) error

func (*Response) UnmarshalResult

func (r *Response) UnmarshalResult(payload any) error

type ResponseFuture

type ResponseFuture = async.Future[async.Result[*Response]]

type ResponseOption

type ResponseOption = func(opts *ResponseOptions) error

func ResponseNumericId

func ResponseNumericId(id int) ResponseOption

func ResponseStringId

func ResponseStringId(id string) ResponseOption

func ResponseVersion

func ResponseVersion(version string) ResponseOption

type ResponseOptions

type ResponseOptions struct {
	Id      json.RawMessage
	Version string
}

func DefaultResponseOptions

func DefaultResponseOptions() ResponseOptions

type WebSocketDialer

type WebSocketDialer struct {
	Url           string
	RequestHeader http.Header
}

func (WebSocketDialer) Dial

func (w WebSocketDialer) Dial() (Connection, error)

func (WebSocketDialer) DialContext

func (w WebSocketDialer) DialContext(ctx context.Context) (Connection, error)

Jump to

Keyboard shortcuts

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