Documentation ¶
Index ¶
- Constants
- Variables
- type BasicAuth
- type BatchElem
- type Client
- type ClientAdapter
- func (c ClientAdapter) BatchCallJsonRpc(b []BatchElem) error
- func (c ClientAdapter) CallJsonRpc(result interface{}, method string, args interface{}) error
- func (c ClientAdapter) Close() error
- func (c ClientAdapter) ErrFromWS() chan error
- func (c ClientAdapter) GetType() ClientType
- func (c ClientAdapter) RawCallHttp(method string, path string, body interface{}) (int, io.ReadCloser, error)
- func (c ClientAdapter) UnderlyingHandle() interface{}
- func (c ClientAdapter) WriteByWs(WSMessage) error
- type ClientOption
- type ClientType
- type Context
- type JsonRpcError
- type JsonRpcNotifier
- type JsonRpcOption
- type JsonRpcRequest
- type JsonRpcResponse
- type RawHttpContext
- type RawHttpHandle
- type RawWSNotifier
- type RawWsHandle
- type ServerOption
- type SubscriptionNotice
- type SubscriptionResult
- type WSMessage
- type WSMessageType
Constants ¶
View Source
const ( HttpClient = iota GrpcClient WsClient )
View Source
const ( Success = 0 // ParseError begin for json-rpc 2.0 ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 ReserveMinError = -32099 ReserveMaxError = -32000 )
View Source
const ( JsonRpcNotifierKey = "_JsonRpcNotifierKey_" RawWSNotifierKey = "_RawWSNotifierKey_" )
View Source
const ( BuiltInPathJsonRPC = "_jsonrpc_" BuiltInPathWsJsonRPC = "_jsonrpc_ws_" BuiltInPathRawWS = "_raw_ws_" BuiltInPathDIR = "_dir_" BuiltInPathMetrics = "_metrics_" )
View Source
const (
Version = "2.0"
)
Variables ¶
View Source
var SysCodeMap = map[int]string{ ParseError: "Parse error", InvalidRequest: "Invalid request", MethodNotFound: "Method not found", InvalidParams: "Invalid params", InternalError: "Internal error", }
Functions ¶
This section is empty.
Types ¶
type BatchElem ¶
type BatchElem struct { Method string Args interface{} // The result is unmarshalled into this field. Result must be set to a // non-nil pointer value of the desired type, otherwise the response will be // discarded. Result interface{} // Error is set if the server returns an error for this request, or if // unmarshalling into Result fails. It is not set for I/O errors. Error error }
BatchElem is an element in a batch request.
type Client ¶
type Client interface { GetType() ClientType CallJsonRpc(result interface{}, method string, args interface{}) error BatchCallJsonRpc(b []BatchElem) error RawCallHttp(method string, path string, body interface{}) (int, io.ReadCloser, error) Close() error // The WriteByWs ending with "WS" are only intended for WebSocket clients WriteByWs(WSMessage) error ErrFromWS() chan error // The UnderlyingHandle is only intended for grpc clients now UnderlyingHandle() interface{} }
type ClientAdapter ¶
type ClientAdapter struct{}
func (ClientAdapter) BatchCallJsonRpc ¶
func (c ClientAdapter) BatchCallJsonRpc(b []BatchElem) error
func (ClientAdapter) CallJsonRpc ¶
func (c ClientAdapter) CallJsonRpc(result interface{}, method string, args interface{}) error
func (ClientAdapter) Close ¶
func (c ClientAdapter) Close() error
func (ClientAdapter) ErrFromWS ¶
func (c ClientAdapter) ErrFromWS() chan error
func (ClientAdapter) GetType ¶
func (c ClientAdapter) GetType() ClientType
func (ClientAdapter) RawCallHttp ¶
func (c ClientAdapter) RawCallHttp(method string, path string, body interface{}) (int, io.ReadCloser, error)
func (ClientAdapter) UnderlyingHandle ¶
func (c ClientAdapter) UnderlyingHandle() interface{}
func (ClientAdapter) WriteByWs ¶
func (c ClientAdapter) WriteByWs(WSMessage) error
type ClientOption ¶
type ClientOption struct { JsonRpcOpt *JsonRpcOption // http auth Basic *BasicAuth // websocket RevChan interface{} }
type ClientType ¶
type ClientType int
type JsonRpcError ¶
type JsonRpcError struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
func FromError ¶
func FromError(err error) (*JsonRpcError, bool)
func NewJsonRpcErrFromCode ¶
func NewJsonRpcErrFromCode(c int, data interface{}) *JsonRpcError
func NewJsonRpcError ¶
func NewJsonRpcError(c int, msg string, data interface{}) *JsonRpcError
func (*JsonRpcError) Error ¶
func (j *JsonRpcError) Error() string
type JsonRpcNotifier ¶
type JsonRpcNotifier interface { Notify(sub *SubscriptionNotice) error ID() string Err() chan error }
type JsonRpcOption ¶
type JsonRpcRequest ¶
type JsonRpcRequest struct { Version string `json:"jsonrpc"` Method string `json:"method"` // Params should be json.RawMessage. However, in fact, since the params parameter in the request body is already // an interface after the data is deserialized into a map, if it is set to json.rawMessage, // essentially a conversion process is required. In other words, the type of the value in map after deserialization // is interface{}, and the interface{} cannot be forced to be converted to json.RawMessage Params interface{} `json:"params,omitempty"` Id interface{} `json:"id"` }
type JsonRpcResponse ¶
type JsonRpcResponse struct { Version string `json:"jsonrpc"` Id interface{} `json:"id"` Result json.RawMessage `json:"result,omitempty"` Error *JsonRpcError `json:"error,omitempty"` }
func NewErrorJsonRpcResponse ¶
func NewErrorJsonRpcResponse(id interface{}, code int, msg string, data interface{}) *JsonRpcResponse
func NewErrorJsonRpcResponseWithError ¶
func NewErrorJsonRpcResponseWithError(id interface{}, err *JsonRpcError) *JsonRpcResponse
func NewSuccessJsonRpcResponse ¶
func NewSuccessJsonRpcResponse(id interface{}, result interface{}) *JsonRpcResponse
type RawHttpContext ¶
type RawHttpHandle ¶
type RawHttpHandle func(RawHttpContext, []byte)
RawHttpHandle is a raw interface for creating api based http
type RawWSNotifier ¶
type RawWsHandle ¶
RawWsHandle is a raw interface for creating api based ws
type ServerOption ¶
type SubscriptionNotice ¶
type SubscriptionNotice struct { Version string `json:"jsonrpc"` Method string `json:"method"` Params SubscriptionResult `json:"params,omitempty"` }
func NewSubscriptionNotice ¶
func NewSubscriptionNotice(method string, id interface{}, result interface{}) *SubscriptionNotice
type SubscriptionResult ¶
type SubscriptionResult struct { ID interface{} `json:"subscription"` Result json.RawMessage `json:"result,omitempty"` }
type WSMessage ¶
type WSMessage struct { Type WSMessageType Data []byte }
type WSMessageType ¶
type WSMessageType int
const ( WSTextMessage WSMessageType = 1 WSBinaryMessage WSMessageType = 2 )
Click to show internal directories.
Click to hide internal directories.