Documentation
¶
Index ¶
- Constants
- func AsRequestIntId(r RequestId) (int, bool)
- type BatchRequest
- type BatchResponse
- type Error
- func NewError(code int, message string, data interface{}) *Error
- func NewInternalError(message string, data []byte) *Error
- func NewInvalidParamsError(message string, data []byte) *Error
- func NewInvalidRequest(message string, data []byte) *Error
- func NewMethodNotFound(message string, data []byte) *Error
- func NewParsingError(message string, data []byte) *Error
- type Listener
- type Logger
- type Message
- type MessageType
- type Notification
- type Request
- type RequestId
- type Response
- type StdLogger
- type TypedRequest
Constants ¶
const ( ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 )
const RequestIdKey = requestId("jsonrpc-request-id")
SessionKey is the key used to store the session ID in the context.
const SessionKey = sessionKey("jsonrpc-session")
SessionKey is the key used to store the session ID in the context.
const Version = "2.0"
Version is the JSON-RPC protocol version.
Variables ¶
This section is empty.
Functions ¶
func AsRequestIntId ¶ added in v0.6.2
Types ¶
type BatchRequest ¶
type BatchRequest []*Request
BatchRequest represents a JSON-RPC 2.0 batch request as per specs
func (*BatchRequest) UnmarshalJSON ¶
func (b *BatchRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON is a custom JSON unmarshaler for the BatchRequest type
type BatchResponse ¶
type BatchResponse []*Response
BatchResponse represents a JSON-RPC 2.0 batch response as per specs
type Error ¶
type Error struct { // The error type that occurred. Code int `json:"code" yaml:"code" mapstructure:"code"` // Additional information about the error. The value of this member is defined by // the sender (e.g. detailed error information, nested errors etc.). Data json.RawMessage `json:"data,omitempty" yaml:"data,omitempty" mapstructure:"data,omitempty"` // A short description of the error. The message SHOULD be limited to a concise // single sentence. Message string `json:"message" yaml:"message" mapstructure:"message"` }
Error is used to provide additional information about the error that occurred.
func NewInternalError ¶
NewInternalError creates a new internal error
func NewInvalidParamsError ¶
NewInvalidParamsError creates a new invalid params error
func NewInvalidRequest ¶
NewInvalidRequest creates a new invalid request error
func NewMethodNotFound ¶
NewMethodNotFound creates a new invalid request error
func NewParsingError ¶
NewParsingError creates a new parsing error
type Logger ¶
type Logger interface { // Errorf logs an error message with formatting Errorf(format string, args ...interface{}) }
Logger defines the interface for logging operations
var DefaultLogger Logger = NewStdLogger(os.Stderr)
DefaultLogger is the default logger instance that writes to os.Stderr
type Message ¶
type Message struct { Type MessageType JsonRpcRequest *Request JsonRpcNotification *Notification JsonRpcResponse *Response }
Message is a wrapper around the different types of JSON-RPC messages (Request, Notification, Response, Error).
func NewNotificationMessage ¶
func NewNotificationMessage(notification *Notification) *Message
NewNotificationMessage creates a new JSON-RPC message of type Notification.
func NewRequestMessage ¶
NewRequestMessage creates a new JSON-RPC message of type Request.
func NewResponseMessage ¶
NewResponseMessage creates a new JSON-RPC message of type Response.
func (*Message) MarshalJSON ¶
MarshalJSON is a custom JSON marshaler for the Message type.
type MessageType ¶
type MessageType string
MessageType is an enumeration of the types of messages in the JSON-RPC protocol.
const ( MessageTypeRequest MessageType = "request" MessageTypeNotification MessageType = "notification" MessageTypeResponse MessageType = "response" )
type Notification ¶
type Notification struct { // Jsonrpc corresponds to the JSON schema field "jsonrpc". Jsonrpc string `json:"jsonrpc" yaml:"jsonrpc" mapstructure:"jsonrpc"` // Method corresponds to the JSON schema field "method". Method string `json:"method" yaml:"method" mapstructure:"method"` // Params corresponds to the JSON schema field "params". // It is stored as a []byte to enable efficient marshaling and unmarshaling into custom types later on in the protocol Params json.RawMessage `json:"params,omitempty" yaml:"params,omitempty" mapstructure:"params,omitempty"` }
Notification is a type representing a JSON-RPC notification message.
func NewNotification ¶ added in v0.5.0
func NewNotification(method string, params interface{}) (*Notification, error)
NewNotification creates a new Notification instance with the specified method and params.
func (*Notification) UnmarshalJSON ¶
func (m *Notification) UnmarshalJSON(data []byte) error
UnmarshalJSON is a custom JSON unmarshaler for the Notification type.
type Request ¶
type Request struct { // Id corresponds to the JSON schema field "id". Id RequestId `json:"id,omitempty" yaml:"id" mapstructure:"id"` // Jsonrpc corresponds to the JSON schema field "jsonrpc". Jsonrpc string `json:"jsonrpc" yaml:"jsonrpc" mapstructure:"jsonrpc"` // Method corresponds to the JSON schema field "method". Method string `json:"method" yaml:"method" mapstructure:"method"` // Params corresponds to the JSON schema field "params". // It is stored as a []byte to enable efficient marshaling and unmarshaling into custom types later on in the protocol Params json.RawMessage `json:"params,omitempty" yaml:"params,omitempty" mapstructure:"params,omitempty"` }
Request represents a JSON-RPC request message.
func NewRequest ¶
func (*Request) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON unmarshaler for the Request type.
type RequestId ¶
type RequestId any
RequestId is the type used to represent the id of a JSON-RPC request.
type Response ¶
type Response struct { // Id corresponds to the JSON schema field "id". Id RequestId `json:"id" yaml:"id" mapstructure:"id"` // Jsonrpc corresponds to the JSON schema field "jsonrpc". Jsonrpc string `json:"jsonrpc" yaml:"jsonrpc" mapstructure:"jsonrpc"` //Error Error *Error `json:"error,omitempty" yaml:"error,omitempty" mapstructure:"error"` // Result corresponds to the JSON schema field "result". Result json.RawMessage `json:"result,omitempty" yaml:"result,omitempty" mapstructure:"result"` }
func NewResponse ¶
NewResponse creates a new Response instance with the specified id and data.
func (*Response) UnmarshalJSON ¶
UnmarshalJSON is a custom JSON unmarshaler for the Response type.
type StdLogger ¶
type StdLogger struct {
// contains filtered or unexported fields
}
StdLogger is a simple logger that writes to an io.Writer
func NewStdLogger ¶
NewStdLogger creates a new StdLogger with the specified writer If writer is nil, os.Stderr is used as the default
type TypedRequest ¶ added in v0.7.0
type TypedRequest[T any] struct { Id uint64 `json:"request_id"` Method string `json:"method"` Request T }
TypedRequest repesents typed reuquest