Documentation
¶
Overview ¶
Package jsonrpc provides primitives to serve JSON-RPC requests.
Index ¶
Constants ¶
View Source
const NotificationCancelRequest = "$/cancelRequest"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
func WrapError ¶
WrapError wraps error as json-rpc error.
If error is jsonrpc.Error - returns original value.
func (*Error) AsResponse ¶
type Interceptor ¶
type Interceptor interface {
InterceptRequest(ctx context.Context, req Request, next Interceptor) *Response
}
type Request ¶
type Request struct {
ID int `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
type RequestHandler ¶
type RequestHandler interface {
HandleRequest(ctx context.Context, params json.RawMessage) (any, error)
}
func NewHandler ¶
func NewHandler[TRequest, TResponse any](fn func(ctx context.Context, req TRequest) (*TResponse, error)) RequestHandler
NewHandler constructs a new type-safe request handler.
Incoming request is automatically parsed into a [TRequest] type.
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
func NewServeMux ¶
func NewServeMux(handlers map[string]RequestHandler) *ServeMux
func (*ServeMux) ServeStream ¶
ServeStream handles incoming requests from a given connection.
func (*ServeMux) SetInterceptor ¶
func (mux *ServeMux) SetInterceptor(interceptor Interceptor)
SetInterceptor adds request interceptors.
Click to show internal directories.
Click to hide internal directories.