Documentation
¶
Overview ¶
Package jsonrpc2 provides a JSON-RPC 2.0-compatible stream implementation.
Index ¶
Constants ¶
const ( // ErrorCodeParseError is the error code for parsing errors. ErrorCodeParseError = -32700 // ErrorCodeInvalidRequest is the error code for invalid request errors. ErrorCodeInvalidRequest = -32600 // ErrorCodeMethodNotFound is the error code for method not found errors. ErrorCodeMethodNotFound = -32601 // ErrorCodeInvalidParams is the error code for invalid params errors. ErrorCodeInvalidParams = -32602 // ErrorCodeInternalError is the error code for internal errors. ErrorCodeInternalError = -32603 // ErrorCodeServerError is the error code for server errors. ErrorCodeServerError = -32000 )
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 *json.RawMessage `json:"data,omitempty"`
}
Error represents a JSON-RPC error. For more information, see the specification.
type ErrorCode ¶
type ErrorCode int
ErrorCode represents a JSON-RPC error code. For more information, see the specification.
type Handler ¶
type Handler interface {
Handle(method string, params json.RawMessage) (json.RawMessage, *Error)
GetShutdownChan() chan struct{}
}
Handler represents a JSON-RPC handler.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
ID RequestID `json:"id"`
}
Request represents a JSON-RPC request. For more information, see the specification.
func NewRequest ¶
func NewRequest(method string, params json.RawMessage) *Request
NewRequest creates a new JSON-RPC request.
type RequestID ¶
type RequestID struct {
// contains filtered or unexported fields
}
RequestID represents a JSON-RPC request ID.
func NewRequestID ¶
func NewRequestID(value json.RawMessage) *RequestID
NewRequestID creates a new JSON-RPC request ID.
func (*RequestID) MarshalJSON ¶
MarshalJSON marshals the RequestID to JSON.
func (*RequestID) UnmarshalJSON ¶
UnmarshalJSON unmarshals JSON into the RequestID.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
Result json.RawMessage `json:"result,omitempty"`
Error json.RawMessage `json:"error,omitempty"`
ID RequestID `json:"id"`
}
Response represents a JSON-RPC response. For more information, see the specification.
func NewErrorResponse ¶
NewErrorResponse creates a new JSON-RPC error response.
func NewResponse ¶
func NewResponse(result json.RawMessage, id RequestID) *Response
NewResponse creates a new JSON-RPC response.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the JSON-RPC server.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream represents the JSON-RPC stream.
func (*Stream) ReadMessage ¶
ReadMessage reads a message from the stream.
func (*Stream) WriteMessage ¶
WriteMessage writes a message to the stream.