jsonrpc

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

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 8 Imported by: 0

README

jsonrpc

A JSON RPC tool kit

Documentation

Index

Constants

View Source
const (
	ErrorCodeParseError     = -32700
	ErrorCodeInvalidRequest = -32600
	ErrorCodeMethodNotFound = -32601
	ErrorCodeInvalidParams  = -32602
	ErrorCodeInternalError  = -32603
	ErrorCodeServerError    = -32000
)

Variables

This section is empty.

Functions

func DefaultRequestEncoder

func DefaultRequestEncoder(req Request, w io.Writer) error

func DefaultResponseEncoder

func DefaultResponseEncoder(resp Response, w io.Writer) error

func IterJsonArray

func IterJsonArray(data []byte) iter.Seq2[int, json.RawMessage]

func IterJsonObject

func IterJsonObject(data []byte) iter.Seq2[string, json.RawMessage]

func NewServer

func NewServer() *defaultServer

Types

type Error

type Error interface {
	error
	Code() int
	Message() string
	Data() any
}

func NewError

func NewError(code int, message string, data any) Error

returns a new error

type Id

type Id interface {
	String() (string, bool)
	Int() (int, bool)
	IsNull() bool
	json.Marshaler
}

func NewIdInt

func NewIdInt(i int64) Id

func NewIdStr

func NewIdStr(s string) Id

func NullId

func NullId() Id

type JsonRpcServer

type JsonRpcServer interface {
	ServeJsonRpc(req Request) Response
	Register(string, any) error
}

type Params

type Params interface {
	ByPosition() bool
	ByName() bool
	DecodeInto(any) error
	json.Marshaler
}

func NewParamsMap

func NewParamsMap[T any](m map[string]T) Params

func NewParamsSlice

func NewParamsSlice[T any](s []T) Params

NewPositionalParams() ??? make variadic???

type Request

type Request interface {
	Jsonrpc() string
	Method() string
	Params() Params
	Id() Id
}

func DefaultRequestdecoder

func DefaultRequestdecoder(r io.Reader) (Request, error)

func NewNotification

func NewNotification(method string, params Params) Request

func NewRequest

func NewRequest(method string, params Params, id Id) Request

type RequestDecoder

type RequestDecoder func(io.Reader) (Request, error)

type RequestEncoder

type RequestEncoder func(Request, io.Writer) error

type Response

type Response interface {
	Jsonrpc() string
	Result() any
	Error() Error
	Id() Id
}

func DefaultResponseDecoder

func DefaultResponseDecoder(r io.Reader) (Response, error)

func NewErrorResponse

func NewErrorResponse(error Error, id Id) Response

func NewSuccessResponse

func NewSuccessResponse(result any, id Id) Response

type ResponseDecoder

type ResponseDecoder func(io.Reader) (Response, error)

type ResponseEncoder

type ResponseEncoder func(Response, io.Writer) error

Jump to

Keyboard shortcuts

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