Documentation
¶
Index ¶
Constants ¶
const ProtocolVersion = "2.0"
ProtocolVersion is the supported JSON-RPC protocol version.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnyMessage ¶
type AnyMessage struct {
JSONRPCVersion string `json:"jsonrpc"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
ID *RequestID `json:"id,omitempty"`
}
AnyMessage is a generic JSON-RPC message (request, notification, or response).
func (*AnyMessage) AsRequest ¶
func (m *AnyMessage) AsRequest() *Request
AsRequest returns the message as a Request if it is a request message, otherwise nil
func (*AnyMessage) AsResponse ¶
func (m *AnyMessage) AsResponse() *Response
AsResponse returns the message as a Response if it is a response message, otherwise nil
func (*AnyMessage) Type ¶
func (m *AnyMessage) Type() string
Type returns "request" if the message is a request, "response" if it's a response, or "notification" if it's a notification
func (*AnyMessage) UnmarshalJSON ¶
func (m *AnyMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling for AnyMessage It enforces JSON-RPC 2.0 semantics and validates message structure
type Error ¶
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
Error is a JSON-RPC error object.
type ErrorCode ¶
type ErrorCode int
ErrorCode is a JSON-RPC 2.0 error code.
const ( // ErrorCodeParseError indicates invalid JSON was received by the server. ErrorCodeParseError ErrorCode = -32700 // ErrorCodeInvalidRequest indicates the JSON sent is not a valid Request object. ErrorCodeInvalidRequest ErrorCode = -32600 // ErrorCodeMethodNotFound indicates the method does not exist / is not available. ErrorCodeMethodNotFound ErrorCode = -32601 // ErrorCodeInvalidParams indicates invalid method parameters. ErrorCodeInvalidParams ErrorCode = -32602 // ErrorCodeInternalError indicates an internal JSON-RPC error. ErrorCodeInternalError ErrorCode = -32603 )
type Request ¶
type Request struct {
JSONRPCVersion string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
ID *RequestID `json:"id,omitempty"`
}
Request represents a JSON-RPC request (with an ID) or notification (without ID).
type RequestID ¶
type RequestID struct {
// contains filtered or unexported fields
}
RequestID represents a JSON-RPC ID that can be either a string or a number
func NewRequestID ¶
func NewRequestID(value interface{}) *RequestID
NewRequestID creates a new JSONRPCId from a string or number
func (*RequestID) MarshalJSON ¶
MarshalJSON implements json.Marshaler
func (*RequestID) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler
type Response ¶
type Response struct {
JSONRPCVersion string `json:"jsonrpc"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
ID *RequestID `json:"id,omitempty"`
}
Response represents a JSON-RPC response.
func NewErrorResponse ¶
NewErrorResponse builds an error JSON-RPC response with the given code.