Documentation ¶
Index ¶
- func DecodeJSON(raw json.RawMessage, v interface{}) error
- func EncodeJSON(v interface{}) (json.RawMessage, error)
- func NewConn(parentCtx context.Context, transport Transport, handler Handler) *connImpl
- type Conn
- type Error
- type ErrorCode
- type Handler
- type ID
- type Message
- type Notification
- type OutgoingCall
- type ReadWriteClose
- type Request
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
func DecodeJSON(raw json.RawMessage, v interface{}) error
Decode anything from JSON
func EncodeJSON ¶
func EncodeJSON(v interface{}) (json.RawMessage, error)
Encode anything as JSON, but marshal nil slices as [], and nil maps as {}
Types ¶
type Error ¶
type Error struct { Code ErrorCode `json:"code"` Message string `json:"message"` Data *json.RawMessage `json:"data"` }
A JSON-RPC 2.0 error, see https://www.jsonrpc.org/specification#error_object
type Handler ¶
type Handler interface { // Handle a request, returning either a result or an error (but not both) // If both are returned, a non-nil Error takes priority HandleRequest(conn Conn, req Request) (interface{}, error) // Handle a notification, returning nothing. HandleNotification(conn Conn, notif Notification) }
A Handler reacts to incoming requests or notifications
type Message ¶
type Message struct { // *must* be set to "2.0" JsonRPC string `json:"jsonrpc"` // can be nil if notification or id-less error ID *ID `json:"id,omitempty"` // can be nil if result / error Method *string `json:"method,omitempty"` // can be nil if response Params *json.RawMessage `json:"params,omitempty"` // can be nil if request / notification Result *json.RawMessage `json:"result,omitempty"` // can be nil if success Error *Error `json:"error,omitempty"` }
type Notification ¶
type Notification struct { Method string Params *json.RawMessage }
A JSON-RPC2 notification, see https://www.jsonrpc.org/specification#notification
type OutgoingCall ¶
type OutgoingCall func(msg Message)
type Request ¶
type Request struct { ID ID Method string Params *json.RawMessage }
A JSON-RPC2 request, see https://www.jsonrpc.org/specification#request_object
Click to show internal directories.
Click to hide internal directories.