rpc

package
v0.13.4 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MessageFromJson added in v0.8.0

func MessageFromJson(data []byte, m *Message) error

func NextId

func NextId() uint64

Types

type Connection

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

Connection represents a cancelable websocket connection.

func Dial added in v0.8.0

func Dial(ctx context.Context, url string) (*Connection, error)

Dial creates a new client connection. It tries repeatedly to connect to the server until successful or context is done.

func NewConnection

func NewConnection(ctx context.Context, socket *websocket.Conn) *Connection

NewConnection handles a new websocket

func (*Connection) Close added in v0.8.0

func (c *Connection) Close()

Close closes the connection and the underlying socket.

func (*Connection) Done added in v0.8.0

func (c *Connection) Done() <-chan struct{}

Done returns a channel that is closed when the connection is closed.

func (*Connection) Id added in v0.8.0

func (c *Connection) Id() string

Id returns the connection id.

func (*Connection) Read added in v0.8.0

func (c *Connection) Read() []byte

func (*Connection) ReadJSON added in v0.8.0

func (c *Connection) ReadJSON(v interface{}) error

func (*Connection) Write added in v0.8.0

func (c *Connection) Write(data []byte)

func (*Connection) WriteJSON added in v0.8.0

func (c *Connection) WriteJSON(v interface{}) error

type Hub

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

func NewHub

func NewHub(ctx context.Context) *Hub

func (*Hub) Broadcast added in v0.8.0

func (h *Hub) Broadcast(data []byte)

Broadcast sends data to all connections

func (*Hub) BroadcastJSON added in v0.8.0

func (h *Hub) BroadcastJSON(v interface{}) error

BroadcastJSON encodes v as JSON and broadcasts it to all connections.

func (*Hub) Requests added in v0.8.0

func (h *Hub) Requests() <-chan *Request

func (*Hub) ServeHTTP added in v0.8.0

func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Message added in v0.8.0

type Message struct {
	Version string         `json:"version"`
	Method  string         `json:"method"`
	Id      uint64         `json:"id"`
	Params  map[string]any `json:"params"`
	Result  any            `json:"result"`
	Error   RpcError       `json:"error,omitempty"`
}

func MakeCall

func MakeCall(method string, id uint64, params map[string]any) Message

func MakeError

func MakeError(code int, msg string) Message

func MakeNotify

func MakeNotify(method string, params map[string]any) Message

func MakeResult

func MakeResult(id uint64, result any) Message

type MessageHandler added in v0.8.0

type MessageHandler interface {
	HandleMessage(m Message) error
}

type Request added in v0.8.0

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

Request represents a request from a client.

func (Request) AsData added in v0.8.0

func (r Request) AsData() []byte

AsData returns the request data as a string.

func (Request) AsJSON added in v0.8.0

func (r Request) AsJSON(v interface{}) error

AsJSON decodes the request data as JSON.

func (Request) Broadcast added in v0.8.0

func (r Request) Broadcast(data []byte)

Broadcast sends data to all connections

func (Request) BroadcastJSON added in v0.8.0

func (r Request) BroadcastJSON(v interface{}) error

BroadcastJSON encodes v as JSON and broadcasts it to all connections.

func (Request) Error added in v0.8.0

func (r Request) Error() error

Error returns the error that occurred while processing the request.

func (Request) Reply added in v0.8.0

func (r Request) Reply(data []byte)

Reply writes a response to the client.

func (Request) ReplyJSON added in v0.8.0

func (r Request) ReplyJSON(data interface{}) error

ReplyJSON writes a JSON response to the client.

type RequestHandler added in v0.8.0

type RequestHandler interface {
	HandleRequest(m Request) error
}

type RpcError

type RpcError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

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