rpc

package module
v0.0.0-...-c05f780 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2023 License: MIT Imports: 4 Imported by: 0

README

A minimal JSON-RPC server written directly in Go with no third-party dependencies.

Documentation

Index

Constants

View Source
const JSONRPC_VERSION = "2.0"

Variables

This section is empty.

Functions

func HTTPError

func HTTPError(w http.ResponseWriter, statusCode int, err error)

func UnmarshalParams

func UnmarshalParams[T any](data json.RawMessage) (T, error)

Types

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

func (*Error) Error

func (err *Error) Error() string

type Handler

type Handler struct {
	Methods map[string]Method
}

func (*Handler) HTTPHandler

func (h *Handler) HTTPHandler(w http.ResponseWriter, r *http.Request)

type Method

type Method func(id any, params json.RawMessage) (any, error)

type Request

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

func UnmarshalRequest

func UnmarshalRequest(data []byte) (*Request, error)

type Response

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

func NewResponse

func NewResponse(id any, result any, err error) *Response

func (*Response) Marshal

func (r *Response) Marshal() ([]byte, error)

Directories

Path Synopsis
examples
basic command

Jump to

Keyboard shortcuts

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