Documentation ¶
Index ¶
- Constants
- Variables
- func NewServerError(code int, message string) error
- func NewStandardError(code StandardErrorType) error
- func NewStandardErrorData(code StandardErrorType, data interface{}) error
- type ContextKey
- type Invoker
- type JsonRPCversion
- type JsonRpcProcessor
- type JsonRpcRequest
- type JsonRpcResponse
- type LimitedWriter
- type MethodType
- type NewInvoker
- type RPCResponser
- type RequestDefinition
- type StandardErrorType
- type UserData
Constants ¶
const ( // ParseError code for parse error ParseError StandardErrorType = -32700 // InvalidRequest code for invalid request InvalidRequest = -32600 // MethodNotFound code for method not found MethodNotFound = -32601 // InvalidParams code for invalid params InvalidParams = -32602 // InternalError code for internal error InternalError = -32603 )
Variables ¶
var ( // ErrParseError - Provided data is not JSON ErrParseError = NewStandardError(ParseError) // ErrMethodNotFound - no such method ErrMethodNotFound = NewStandardError(MethodNotFound) // ErrInvalidRequest - Request was invalid ErrInvalidRequest = NewStandardError(InvalidRequest) // ErrTimeout - Timeout during request processing ErrTimeout = NewServerError(-32099, "Timeout") // ErrLimitExceed - Returned when response is too big ErrLimitExceed = NewServerError(-32098, "Limit Exceed") // ErrBatchUnsupported - Returned when batch is disabled ErrBatchUnsupported = NewServerError(-32097, "Batch is disabled") )
Functions ¶
func NewServerError ¶
NewServerError from code and message
func NewStandardError ¶
func NewStandardError(code StandardErrorType) error
NewStandardError from code
func NewStandardErrorData ¶
func NewStandardErrorData(code StandardErrorType, data interface{}) error
NewStandardErrorData with code and custom data
Types ¶
type Invoker ¶
type Invoker interface {
Invoke(context.Context, JsonRpcRequest) (interface{}, error)
}
Invoker is interface for method invoked by rpc server
type JsonRPCversion ¶
type JsonRPCversion string
var ( JsonRPCversion20 JsonRPCversion = "2.0" JsonRPCversion20s = JsonRPCversion20 + "+s" )
type JsonRpcProcessor ¶
type JsonRpcProcessor interface { AddMethod(name string, metype MethodType, action Invoker) *methodDef AddMethodNew(name string, metype MethodType, action NewInvoker) *methodDef AddMethodFunc(name string, metype MethodType, action methodFunc) *methodDef AddMethodFuncNew(name string, metype MethodType, action newMethodFunc) *methodDef Process(request RequestDefinition, response io.Writer) error ProcessContext(ctx context.Context, request RequestDefinition, response io.Writer) error ExecutionTimeout(metype MethodType, timeout time.Duration) }
func NewJsonRpcProcessor ¶
func NewJsonRpcProcessor() JsonRpcProcessor
NewJsonRpcProcessor create new json rpc processor
type JsonRpcRequest ¶
type JsonRpcRequest interface { Method() string Version() JsonRPCversion UserData() UserData Params() jsonRPCRequestOptions }
type JsonRpcResponse ¶
type JsonRpcResponse struct { Jsonrpc JsonRPCversion `json:"jsonrpc"` Error *_Error `json:"error,omitempty"` Result interface{} `json:"result,omitempty"` ID interface{} `json:"id,omitempty"` }
func NewError ¶
func NewError(a error, id interface{}) *JsonRpcResponse
NewError : Generate new error response with JsonRpcversion20
func NewErrorEx ¶
func NewErrorEx(a error, id interface{}, vers JsonRPCversion) *JsonRpcResponse
NewErrorEx : Generate new Error response with custom version
func NewResult ¶
func NewResult(a interface{}, id interface{}) *JsonRpcResponse
NewResult : Generate new Result response
func NewResultEx ¶
func NewResultEx(a, id interface{}, vers JsonRPCversion) *JsonRpcResponse
type LimitedWriter ¶
LimitedWriter returns LimitExceed after reaching limit
func ExceptionalLimitWrite ¶
func ExceptionalLimitWrite(r io.Writer, n int64) LimitedWriter
ExceptionalLimitWrite construct from reader Use <0 to limit it to "2^63-1" bytes (practicaly infinity)
type MethodType ¶
type MethodType int
MethodType : Supported or requested method response format
const ( // RPCMethod : Json RPC 2.0 RPCMethod MethodType = 1 // StreamingMethodLegacy : Basic streaming format without header or footer. Can be base64 encoded. StreamingMethodLegacy MethodType = 2 // StreamingMethod : Line JSON encoding with header and footer StreamingMethod MethodType = 4 )
type NewInvoker ¶
type NewInvoker interface {
Invoke(context.Context, JsonRpcRequest, RPCResponser)
}
This have more sense
type RPCResponser ¶
RPCResponser handles returning results
type RequestDefinition ¶
type RequestDefinition interface { Reader() io.ReadCloser OutputMode() MethodType UserData() UserData }
RequestDefinition ...
type StandardErrorType ¶
type StandardErrorType int
StandardErrorType error code *code message meaning *-32700 Parse error Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text. *-32600 Invalid Request The JSON sent is not a valid Request object. *-32601 Method not found The method does not exist / is not available. *-32602 Invalid params Invalid method parameter(s). *-32603 Internal error Internal JSON-RPC error. *-32000 to -32099 Server error Reserved for implementation-defined server-errors.