rpc

package
v0.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 7 Imported by: 0

README

rpc

websocket based remote process call

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClear      = errors.New("handleMessages closed")
	ErrNotRunning = errors.New("client is not running")
)

Functions

This section is empty.

Types

type Call

type Call struct {
	// contains filtered or unexported fields
}

Call request message send from client to server

func NewCall

func NewCall(id string, method string, params interface{}) *Call

func (*Call) ID

func (c *Call) ID() string

func (*Call) Method

func (c *Call) Method() string

func (*Call) Params

func (c *Call) Params() interface{}

type Codec

type Codec interface {
	Decode([]byte) (Response, error)
	Encode(Request) ([]byte, error)
}

Codec specific how to encode/decode stream data

type Conn

type Conn interface {
	//Call send request from client to server. if r is not nil the
	//Call will be waiting for the server return and set dest via json.Unmarshal
	Call(ctx context.Context, id string, method string, params interface{}, dest interface{}) error
	//Run start a gorotuine loop for notify message from server
	//and call handler for each message
	Run(ctx context.Context, handler Handler)
	//Done being closed if running loop was done
	Done() <-chan struct{}
	//Error return err if running loop stop due to error
	Error() error
	//Close stop the running loop
	Close() error
}

Conn a connection bettwen the client and server

func NewConn

func NewConn(stream Stream) Conn

type Error

type Error struct {
	Code    int
	Message string
}

Error info for result code == 0 means no error

type Handler

type Handler interface {
	Handle(ctx context.Context, n *Notify)
}

type Message

type Message interface {
}

type MsgError

type MsgError struct {
	//Msg is the message return from/send to server
	Msg []byte
	Err error
}

MsgError means the Msg format is not support by the Codec and encode/decode stream data fail

func NewMsgError

func NewMsgError(msg []byte, err error) *MsgError

func (*MsgError) Error

func (me *MsgError) Error() string

func (*MsgError) Is

func (me *MsgError) Is(err error) bool

type Notify

type Notify struct {
	Method string
	Params interface{}
}

Notify subscribe messages from server (kline, orders...)

type Request

type Request interface {
	Message
	ID() string
	Method() string
	Params() interface{}
}

type Response

type Response interface {
	Message
	// contains filtered or unexported methods
}

type Result

type Result struct {
	ID     string
	Error  error
	Result json.RawMessage
}

Result call result reply from server the Result field will be parsed via json.Unmarshal

type Stream

type Stream interface {
	Read() (Response, error)
	Write(Request) error
	Close() error
}

Stream which used to read/write messages

func NewWebsocketStream

func NewWebsocketStream(addr string, codec Codec) (Stream, error)

NewWebsocketStream create a new websocket stream with specific codec

type StreamError

type StreamError struct {
	Err error
}

StreamError means there is something wrong with Stream underlying transport layer. StreamError will make conn being closed

func NewStreamError

func NewStreamError(err error) *StreamError

func (*StreamError) Error

func (ce *StreamError) Error() string

func (*StreamError) Is

func (ce *StreamError) Is(err error) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL