Documentation
¶
Index ¶
- Constants
- type DefaultTransport
- func (dt *DefaultTransport) Read() ([]byte, int64, error)
- func (dt *DefaultTransport) SendErrorResponse(id *ID, err *Error)
- func (dt *DefaultTransport) SendNotification(method string, data []byte)
- func (dt *DefaultTransport) SendResponse(id *ID, data []byte)
- func (dt *DefaultTransport) Write(data []byte) (int64, error)
- type Error
- type ID
- type Request
- type Response
- type Stream
- type Transport
- type VersionTag
Constants ¶
const ( // CodeParseError means an invalid JSON was received by the server. // An error occurred on the server while parsing the JSON text. CodeParseError = -32700 //CodeInvalidRequest means the JSON sent is not a valid Request object. CodeInvalidRequest = -32600 // CodeMethodNotFound is generated when the method does not exist / is not available. CodeMethodNotFound = -32601 // CodeInvalidParams means invalid method parameter(s) were found. CodeInvalidParams = -32602 // CodeInternalError is used to denote internal JSON-RPC error CodeInternalError = -32603 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultTransport ¶ added in v0.0.5
type DefaultTransport struct {
// contains filtered or unexported fields
}
DefaultTransport is a default implementation of the `Transport` interface
func MakeTransport ¶ added in v0.0.5
func MakeTransport(io Stream) *DefaultTransport
MakeTransport creates a default transport mechanism over a `Stream`
func (*DefaultTransport) Read ¶ added in v0.0.5
func (dt *DefaultTransport) Read() ([]byte, int64, error)
func (*DefaultTransport) SendErrorResponse ¶ added in v0.0.5
func (dt *DefaultTransport) SendErrorResponse(id *ID, err *Error)
func (*DefaultTransport) SendNotification ¶ added in v0.0.5
func (dt *DefaultTransport) SendNotification(method string, data []byte)
func (*DefaultTransport) SendResponse ¶ added in v0.0.5
func (dt *DefaultTransport) SendResponse(id *ID, data []byte)
SendResponse sends
type Error ¶
type Error struct { Code int64 `json:"code"` Message string `json:"message"` Data *json.RawMessage `json:"data"` }
Error is a JSON RPC 2.0 Error see https://www.jsonrpc.org/specification for details
type ID ¶
ID is a Request identifier, which is either a number or string
func (*ID) MarshalJSON ¶
MarshalJSON converts ID to JSON using the String representation first if it has a non-zero value, otherwise uses the Number value
func (*ID) UnmarshalJSON ¶
UnmarshalJSON decodes JSON RPC 2.0 ID
type Request ¶
type Request struct { Version VersionTag `json:"jsonrpc"` ID *ID `json:"id,omitempty"` Method string `json:"method"` Params *json.RawMessage `json:"params,omitempty"` }
Request is a JSON RPC 2.0 Request. If an ID is not present then it is a notification see https://www.jsonrpc.org/specification for details
type Response ¶
type Response struct { Version VersionTag `json:"jsonrpc"` ID *ID `json:"id,omitempty"` Result *json.RawMessage `json:"result,omitempty"` Error *Error `json:"error,omitempty"` }
Response is a JSON RPC 2.0 Response see https://www.jsonrpc.org/specification for details
type Stream ¶ added in v0.0.5
type Stream interface { //Read gets the next message from the stream Read() (data []byte, length int64, err error) Write(data []byte) (n int64, err error) }
Stream is a transport abstraction free IO Stream for JSON-RPC 2.0
type Transport ¶ added in v0.0.5
type Transport interface { SendResponse(id *ID, data []byte) SendNotification(data []byte) SendErrorResponse(id *ID, err *Error) }
Transport is a protocol-agnostic transport interface for JSON RPC 2.0 messages
type VersionTag ¶
type VersionTag struct { }
VersionTag encodes the JSON RPC 2.0 protocol version
func (VersionTag) MarshalJSON ¶
func (VersionTag) MarshalJSON() ([]byte, error)
MarshalJSON encodes the JSON RPC 2.0 protocol number
func (VersionTag) UnmarshalJSON ¶
func (VersionTag) UnmarshalJSON(js []byte) error
UnmarshalJSON decodes version, and errors if anything other than 2.0 is found