Documentation ¶
Index ¶
- Constants
- Variables
- type API
- type Command
- type ErrorCode
- type ErrorDetails
- func NewCustomError(code ErrorCode, message string, data error) *ErrorDetails
- func NewInternalError(data error) *ErrorDetails
- func NewInvalidParams(data error) *ErrorDetails
- func NewInvalidRequest(data error) *ErrorDetails
- func NewMethodNotFound(data error) *ErrorDetails
- func NewParseError(data error) *ErrorDetails
- func NewServerError(code ErrorCode, data error) *ErrorDetails
- type Params
- type Request
- type RequestMetadata
- type Response
- type Result
Constants ¶
View Source
const JSONRPC2 string = "2.0"
Variables ¶
View Source
var ( ErrOnlySupportJSONRPC2 = errors.New("the API only supports JSON-RPC 2.0") ErrMethodIsRequired = errors.New("the method is required") )
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
func (*API) DispatchRequest ¶
func (*API) RegisterMethod ¶
func (*API) RegisteredMethods ¶
type Command ¶
type Command interface {
Handle(ctx context.Context, params Params, metadata RequestMetadata) (Result, *ErrorDetails)
}
type ErrorCode ¶
type ErrorCode int16
const ( // ErrorCodeParseError Invalid JSON was received by the server. An error // occurred on the server while parsing the JSON text. ErrorCodeParseError ErrorCode = -32700 // ErrorCodeInvalidRequest The JSON sent is not a valid Request object. ErrorCodeInvalidRequest ErrorCode = -32600 // ErrorCodeMethodNotFound The method does not exist / is not available. ErrorCodeMethodNotFound ErrorCode = -32601 // ErrorCodeInvalidParams Invalid method parameter(s). ErrorCodeInvalidParams ErrorCode = -32602 // ErrorCodeInternalError Internal JSON-RPC error. ErrorCodeInternalError ErrorCode = -32603 // ErrorCodeRequestHasBeenInterrupted refers to a request that has been // interrupted by the server or the third-party application. It could // originate from a timeout or an explicit cancellation. ErrorCodeRequestHasBeenInterrupted ErrorCode = -32001 )
type ErrorDetails ¶
type ErrorDetails struct { // Code indicates the error type that occurred. Code ErrorCode `json:"code"` // Message provides a short description of the error. // The message SHOULD be limited to a concise single sentence. Message string `json:"message"` // Data is a primitive or a structured value that contains additional // information about the error. This may be omitted. // The value of this member is defined by the Server (e.g. detailed error // information, nested errors etc.). Data string `json:"data,omitempty"` }
ErrorDetails is returned when an RPC call encounters an error.
func NewCustomError ¶
func NewCustomError(code ErrorCode, message string, data error) *ErrorDetails
func NewInternalError ¶
func NewInternalError(data error) *ErrorDetails
func NewInvalidParams ¶
func NewInvalidParams(data error) *ErrorDetails
func NewInvalidRequest ¶
func NewInvalidRequest(data error) *ErrorDetails
func NewMethodNotFound ¶
func NewMethodNotFound(data error) *ErrorDetails
func NewParseError ¶
func NewParseError(data error) *ErrorDetails
func NewServerError ¶
func NewServerError(code ErrorCode, data error) *ErrorDetails
func (ErrorDetails) Error ¶ added in v0.63.0
func (d ErrorDetails) Error() string
func (ErrorDetails) IsInternalError ¶
func (d ErrorDetails) IsInternalError() bool
type Params ¶
type Params interface{}
Params is just a nicer way to describe what's passed to the handlers.
type Request ¶
type Request struct { // Version specifies the version of the JSON-RPC protocol. // MUST be exactly "2.0". Version string `json:"jsonrpc"` // Method contains the name of the method to be invoked. Method string `json:"method"` // Params is a by-name Structured value that holds the parameter values to be // used during the invocation of the method. This member MAY be omitted. Params Params `json:"params,omitempty"` // ID is an identifier established by the Client that MUST contain a String. // If it is not included it is assumed to be a notification. // The Server MUST reply with the same value in the Response object if included. // This member is used to correlate the context between the two objects. ID string `json:"id,omitempty"` }
func (*Request) IsNotification ¶
type RequestMetadata ¶ added in v0.63.0
type Response ¶
type Response struct { // Version specifies the version of the JSON-RPC protocol. // MUST be exactly "2.0". Version string `json:"jsonrpc"` // Result is REQUIRED on success. This member MUST NOT exist if there was an // error invoking the method. Result Result `json:"result,omitempty"` // Error is REQUIRED on error. This member MUST NOT exist if there was no // error triggered during invocation. Error *ErrorDetails `json:"error,omitempty"` // ID is an identifier established by the Client that MUST contain a String. // This member is REQUIRED. It MUST be the same as the value of the id member // in the Request Object. // If there was an error in detecting the id in the Request object (e.g. // Parse error/Invalid Request), it MUST be empty. ID string `json:"id,omitempty"` }
func NewErrorResponse ¶
func NewErrorResponse(id string, details *ErrorDetails) *Response
func NewSuccessfulResponse ¶
Click to show internal directories.
Click to hide internal directories.