Versions in this module Expand all Collapse all v1 v1.0.0 Aug 25, 2026 Changes in this version + const CodeInternalError + const CodeInvalidParams + const CodeInvalidRequest + const CodeMethodNotFound + const CodeParseError + const CodeRequestLimitExceeded + const Version + var ErrClientResponseTooLarge = errors.New("jsonrpc: client response too large") + var ErrDuplicateRequestID = errors.New("jsonrpc: duplicate batch request id") + var ErrDuplicateResponse = errors.New("jsonrpc: duplicate batch response") + var ErrEmptyBatch = errors.New("jsonrpc: empty client batch") + var ErrHTTPContentType = errors.New("jsonrpc: invalid HTTP response content type") + var ErrHTTPStatus = errors.New("jsonrpc: unexpected HTTP status") + var ErrInvalidMethodName = errors.New("jsonrpc: invalid method name") + var ErrInvalidResponse = errors.New("jsonrpc: invalid response") + var ErrMethodAlreadyRegistered = errors.New("jsonrpc: method already registered") + var ErrMismatchedID = errors.New("jsonrpc: mismatched response id") + var ErrMissingResponse = errors.New("jsonrpc: missing batch response") + var ErrNilHandler = errors.New("jsonrpc: nil handler") + var ErrResponseTooLarge = errors.New("jsonrpc: HTTP response too large") + var ErrTransport = errors.New("jsonrpc: transport error") + var ErrUnexpectedResponse = errors.New("jsonrpc: unexpected response") + func Call[T any](ctx context.Context, client *Client, method string, params any) (T, error) + func IsJSONContentType(value string) bool + type AtomicIDGenerator struct + func NewAtomicIDGenerator(start int64) *AtomicIDGenerator + func (generator *AtomicIDGenerator) NextID() ID + type BatchCall struct + Error *Error + Method string + Notification bool + Params any + Result any + type Client struct + func NewClient(transport Transport, options ...ClientOption) *Client + func (client *Client) Batch(ctx context.Context, calls ...*BatchCall) error + func (client *Client) Call(ctx context.Context, method string, params, result any) error + func (client *Client) Notify(ctx context.Context, method string, params any) error + type ClientOption func(*Client) + func WithIDGenerator(generator IDGenerator) ClientOption + func WithMaxClientResponseBytes(limit int64) ClientOption + type Dispatcher struct + func NewDispatcher(registry *Registry, options ...DispatcherOption) *Dispatcher + func (d *Dispatcher) Dispatch(ctx context.Context, payload []byte) ([]byte, bool) + func (d *Dispatcher) DispatchSingle(ctx context.Context, payload []byte) (Response, bool) + type DispatcherOption func(*Dispatcher) + func WithErrorMapper(mapper ErrorMapper) DispatcherOption + func WithHooks(hooks Hooks) DispatcherOption + func WithMaxBatchItems(limit int) DispatcherOption + func WithMaxDispatchBytes(limit int64) DispatcherOption + func WithMaxNestingDepth(limit int) DispatcherOption + func WithMiddleware(middleware ...Middleware) DispatcherOption + type Error struct + Code int + Data json.RawMessage + Message string + func DecodeParams[T any](params json.RawMessage) (T, *Error) + func InternalError() *Error + func InvalidParams() *Error + func InvalidRequest() *Error + func MethodNotFound() *Error + func NewError(code int, message string) *Error + func ParseError() *Error + func RequestLimitExceeded() *Error + func (e *Error) Error() string + func (e *Error) UnmarshalJSON(data []byte) error + func (e *Error) Unwrap() error + func (e *Error) WithCause(cause error) *Error + func (e *Error) WithData(value any) *Error + type ErrorMapper func(error) *Error + type HTTPHandler struct + func NewHTTPHandler(dispatcher *Dispatcher, options ...HTTPHandlerOption) *HTTPHandler + func (h *HTTPHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) + type HTTPHandlerOption func(*HTTPHandler) + func WithMaxRequestBytes(limit int64) HTTPHandlerOption + type HTTPStatusError struct + Body string + StatusCode int + func (err *HTTPStatusError) Error() string + func (err *HTTPStatusError) Unwrap() error + type HTTPTransport struct + func NewHTTPTransport(endpoint string, options ...HTTPTransportOption) (*HTTPTransport, error) + func (transport *HTTPTransport) RoundTrip(ctx context.Context, payload []byte) ([]byte, error) + type HTTPTransportOption func(*HTTPTransport) + func WithHTTPClient(client *http.Client) HTTPTransportOption + func WithHTTPHeader(name, value string) HTTPTransportOption + func WithMaxResponseBytes(limit int64) HTTPTransportOption + type Handler func(context.Context, json.RawMessage) (any, error) + type Hooks struct + OnRequest func(context.Context, *Request) context.Context + OnResponse func(context.Context, *Request, *Response) + type ID struct + func NullID() ID + func NumberID(value json.Number) ID + func StringID(value string) ID + func (id *ID) UnmarshalJSON(data []byte) error + func (id ID) Equal(other ID) bool + func (id ID) Kind() IDKind + func (id ID) MarshalJSON() ([]byte, error) + type IDGenerator interface + NextID func() ID + type IDKind uint8 + const IDMissing + const IDNull + const IDNumber + const IDString + type Middleware func(Handler) Handler + type Registry struct + func NewRegistry() *Registry + func (r *Registry) Lookup(name string) (Handler, bool) + func (r *Registry) Register(name string, handler Handler) error + func (r *Registry) RegisterSystem(name string, handler Handler) error + type Request struct + ID ID + JSONRPC string + Method string + Params json.RawMessage + func NewNotification(method string, params any) (Request, error) + func NewRequest(method string, params any, id ID) (Request, error) + func RequestFromContext(ctx context.Context) (Request, bool) + func (r *Request) UnmarshalJSON(data []byte) error + func (r Request) IsNotification() bool + func (r Request) MarshalJSON() ([]byte, error) + func (r Request) Validate() *Error + type Response struct + Error *Error + ID ID + JSONRPC string + Result json.RawMessage + func (r *Response) UnmarshalJSON(data []byte) error + func (r Response) MarshalJSON() ([]byte, error) + func (r Response) Validate() error + type Transport interface + RoundTrip func(context.Context, []byte) ([]byte, error) + type TransportFunc func(context.Context, []byte) ([]byte, error) + func (function TransportFunc) RoundTrip(ctx context.Context, payload []byte) ([]byte, error)