rpc

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleRequest

func HandleRequest(data []byte, req Requester) error

HandleRequest unmarshals a request byte array and dispatches the request to the requester

func NewEvent

func NewEvent(rid string, event string, data interface{}) []byte

NewEvent creates an encoded event to be sent to the client

Types

type AddEvent

type AddEvent struct {
	Idx   int         `json:"idx"`
	Value interface{} `json:"value"`
	*Resources
}

AddEvent represents a RES-client collection add event https://github.com/resgateio/resgate/blob/master/docs/res-client-protocol.md#collection-add-event

type ChangeEvent

type ChangeEvent struct {
	Values interface{} `json:"values"`
	*Resources
}

ChangeEvent represents a RES-client model change event https://github.com/resgateio/resgate/blob/master/docs/res-client-protocol.md#model-change-event

type ErrorResponse

type ErrorResponse struct {
	Error *reserr.Error `json:"error"`
	ID    *uint64       `json:"id"`
}

ErrorResponse represents a JSON-RPC error response

type Event

type Event struct {
	Event string      `json:"event"`
	Data  interface{} `json:"data,omitempty"`
}

Event represent a RES-client event object https://github.com/resgateio/resgate/blob/master/docs/res-client-protocol.md#event-object

type NewResult

type NewResult struct {
	RID string `json:"rid"`
	*Resources
}

NewResult represents a RES-client result to a new request

type Request

type Request struct {
	Method string          `json:"method"`
	Params json.RawMessage `json:"params"`
	ID     *uint64         `json:"id"`
}

Request represent a RES-client request https://github.com/resgateio/resgate/blob/master/docs/res-client-protocol.md#requests

func (*Request) ErrorResponse

func (r *Request) ErrorResponse(err error) []byte

ErrorResponse encodes an error to a request response

func (*Request) SuccessResponse

func (r *Request) SuccessResponse(result interface{}) []byte

SuccessResponse encodes a result to a request response

type Requester

type Requester interface {
	Send(data []byte)
	GetResource(rid string, callback func(data *Resources, err error))
	SubscribeResource(rid string, callback func(data *Resources, err error))
	UnsubscribeResource(rid string, callback func(ok bool))
	CallResource(rid, action string, params interface{}, callback func(result json.RawMessage, err error))
	AuthResource(rid, action string, params interface{}, callback func(result json.RawMessage, err error))
	NewResource(rid string, params interface{}, callback func(data *NewResult, err error))
}

Requester has the methods required to perform a rpc request

type Resources

type Resources struct {
	Models      map[string]interface{}   `json:"models,omitempty"`
	Collections map[string]interface{}   `json:"collections,omitempty"`
	Errors      map[string]*reserr.Error `json:"errors,omitempty"`
}

Resources holds a resource information to be sent to the client

type Response

type Response struct {
	Result interface{} `json:"result,omitempty"`
	ID     *uint64     `json:"id"`
}

Response represents a RES-client response

type UnsubscribeEvent

type UnsubscribeEvent struct {
	Reason *reserr.Error `json:"reason"`
}

UnsubscribeEvent represents a RES-client unsubscribe event https://github.com/resgateio/resgate/blob/master/docs/res-client-protocol.md#unsubscribe-event

Jump to

Keyboard shortcuts

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