Documentation ¶
Overview ¶
Package rpc 简化[https://github.com/ethereum/go-ethereum]供当前项目使用
Index ¶
- Constants
- Variables
- func EnableDebugErrorOnClient()
- type BatchElem
- type Call
- type Client
- func Dial(ctx context.Context, endpoint string, newCodecFunc NewClientCodecFunc) (client *Client, err error)
- func DialHTTP(ctx context.Context, url *url.URL, newCodecFunc NewClientCodecFunc) *Client
- func DialHTTPWithClient(ctx context.Context, url *url.URL, newCodecFunc NewClientCodecFunc, ...) *Client
- func DialIPC(ctx context.Context, endpoint string, newCodecFunc NewClientCodecFunc) (*Client, error)
- func DialInProc(ctx context.Context, endpoint *Server, newCodecFunc NewClientCodecFunc) *Client
- func NewClient(codec ClientCodec) *Client
- func (c *Client) Bath(ctx context.Context, elems ...BatchElem) error
- func (c *Client) BathAsync(ctx context.Context, done chan *Call, elems ...BatchElem) *Call
- func (c *Client) Call(ctx context.Context, method MessageMethod, result interface{}, ...) (err error)
- func (c *Client) CallAsync(ctx context.Context, done chan *Call, method MessageMethod, result interface{}, ...) *Call
- func (c *Client) Close()
- func (c *Client) Notice(ctx context.Context, method string, params ...interface{}) (err error)
- type ClientCodec
- type ErrorCode
- type ErrorData
- type ErrorMessage
- type Ins
- type MessageError
- type MessageID
- type MessageMethod
- type MessageParams
- type MessageResult
- type NewClientCodecFunc
- type NewServerCodecFunc
- type RawMessage
- type RequestMessage
- type RequestMessages
- type ResponseMessage
- type ResponseMessages
- type Server
- func (s *Server) Accept(listener net.Listener)
- func (s *Server) Register(namespaces string, receiver interface{}) error
- func (s *Server) ServeCodec(ctx context.Context, codec ServerCodec)
- func (s *Server) ServeConn(ctx context.Context, conn io.ReadWriteCloser)
- func (s *Server) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (s *Server) ServeRequest(ctx context.Context, codec ServerCodec) (err error)
- func (s *Server) Shutdown()
- type ServerCodec
Constants ¶
View Source
const MethodSeparator = "."
Variables ¶
View Source
var ( //ErrInvalidRequest The JSON sent is not a valid Request object. ErrInvalidRequest = &preDefinedError{code: -32600, message: "Invalid Request"} //ErrMethodNotFound The method does not exist / is not available. ErrMethodNotFound = &preDefinedError{code: -32601, message: "Method not found"} //ErrInvalidParams Invalid method parameter(s). ErrInvalidParams = &preDefinedError{code: -32602, message: "Invalid params"} //ErrInternalError Internal JSON-RPC error. ErrInternalError = &preDefinedError{code: -32603, message: "Internal error"} //ErrParseError Invalid JSON was received by the server.An error occurred on the server while parsing the JSON text. ErrParseError = &preDefinedError{code: -32700, message: "Parse error"} )
下面定义的错误类型是JSON-RPC内置错误
View Source
var ErrCallbackNameExist = fmt.Errorf("callback name exist")
Functions ¶
func EnableDebugErrorOnClient ¶
func EnableDebugErrorOnClient()
Types ¶
type BatchElem ¶
type BatchElem struct { Method MessageMethod Params []interface{} Result interface{} Error error // contains filtered or unexported fields }
type Client ¶
func DialHTTPWithClient ¶
func DialInProc ¶
func DialInProc(ctx context.Context, endpoint *Server, newCodecFunc NewClientCodecFunc) *Client
func NewClient ¶
func NewClient(codec ClientCodec) *Client
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, method MessageMethod, result interface{}, params ...interface{}) (err error)
type ClientCodec ¶
type ClientCodec interface { WriteRequest(RawMessage) error MarshalRequestParams(...interface{}) (MessageParams, error) MarshalRequest(*RequestMessages) (RawMessage, error) UnmarshalResponse(RawMessage) (*ResponseMessages, error) UnmarshalResponseResult(MessageResult, interface{}) error ReadResponse() (RawMessage, error) Close() error }
type ErrorMessage ¶
type ErrorMessage interface{ RPCErrorMessage() string }
type MessageError ¶
func (*MessageError) Error ¶
func (err *MessageError) Error() string
type MessageID ¶
type MessageID = RawMessage
type MessageMethod ¶
type MessageMethod = string
type MessageParams ¶
type MessageParams = RawMessage
type MessageResult ¶
type MessageResult = RawMessage
type NewClientCodecFunc ¶
type NewClientCodecFunc func(io.ReadWriteCloser) ClientCodec
type NewServerCodecFunc ¶
type NewServerCodecFunc func(io.ReadWriteCloser) ServerCodec
type RawMessage ¶
type RawMessage = []byte
type RequestMessage ¶
type RequestMessage struct { ID MessageID Method MessageMethod Params MessageParams }
func (*RequestMessage) HasValidID ¶
func (rm *RequestMessage) HasValidID() bool
func (*RequestMessage) IsCallBack ¶
func (rm *RequestMessage) IsCallBack() bool
func (*RequestMessage) IsNotification ¶
func (rm *RequestMessage) IsNotification() bool
func (*RequestMessage) ResponseError ¶
func (rm *RequestMessage) ResponseError(err error) *ResponseMessage
func (*RequestMessage) ResponseResult ¶
func (rm *RequestMessage) ResponseResult(result MessageResult) *ResponseMessage
type RequestMessages ¶
type RequestMessages struct { Batch bool Elems []*RequestMessage }
func NewRequestMessages ¶
func NewRequestMessages(messages ...*RequestMessage) *RequestMessages
func (*RequestMessages) Append ¶
func (rms *RequestMessages) Append(m *RequestMessage)
type ResponseMessage ¶
type ResponseMessage struct { ID MessageID Result MessageResult Error *MessageError }
func (*ResponseMessage) HasValidID ¶
func (rm *ResponseMessage) HasValidID() bool
func (*ResponseMessage) IsResponse ¶
func (rm *ResponseMessage) IsResponse() bool
type ResponseMessages ¶
type ResponseMessages struct { Batch bool Elems []*ResponseMessage }
func NewResponseMessages ¶
func NewResponseMessages(messages ...*ResponseMessage) *ResponseMessages
func (*ResponseMessages) Append ¶
func (rms *ResponseMessages) Append(message *ResponseMessage)
type Server ¶
func NewServer ¶
func NewServer(newCodecFunc NewServerCodecFunc) *Server
func (*Server) ServeCodec ¶
func (s *Server) ServeCodec(ctx context.Context, codec ServerCodec)
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(response http.ResponseWriter, request *http.Request)
func (*Server) ServeRequest ¶
func (s *Server) ServeRequest(ctx context.Context, codec ServerCodec) (err error)
ServeRequest 处理单次,不会关闭连接
type ServerCodec ¶
type ServerCodec interface { ReadRequest() (RawMessage, error) UnmarshalRequest(RawMessage) (*RequestMessages, error) UnmarshalRequestParams(MessageParams, Ins) ([]reflect.Value, error) MarshalResponseResult(interface{}) (MessageResult, error) MarshalResponse(*ResponseMessages) (RawMessage, error) WriteResponse(RawMessage) error Close() error }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.