codec

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeleteValue = Value{
	RawMessage: json.RawMessage(`{"action":"delete"}`),
	Type:       ValueTypeDelete,
}

DeleteValue is a predeclared delete action value

Functions

func CreateAuthRequest

func CreateAuthRequest(params interface{}, r AuthRequester, query string, token interface{}, isHTTP bool) []byte

CreateAuthRequest creates a JSON encoded RES-service auth request

func CreateEventQueryRequest

func CreateEventQueryRequest(query string) []byte

CreateEventQueryRequest creates a JSON encoded RES-service event query request

func CreateGetRequest

func CreateGetRequest(query string) []byte

CreateGetRequest creates a JSON encoded RES-service get request

func CreateRequest

func CreateRequest(params interface{}, r Requester, query string, token interface{}, isHTTP bool) []byte

CreateRequest creates a JSON encoded RES-service request

func DecodeAccessResponse

func DecodeAccessResponse(payload []byte) (*AccessResult, *Meta, *reserr.Error)

DecodeAccessResponse decodes a JSON encoded RES-service access response

func DecodeChangeEvent

func DecodeChangeEvent(data json.RawMessage) (map[string]Value, error)

DecodeChangeEvent decodes a JSON encoded RES-service model change event

func DecodeEvent

func DecodeEvent(payload []byte) (json.RawMessage, error)

DecodeEvent decodes a JSON encoded RES-service event

func DecodeLegacyChangeEvent added in v1.2.0

func DecodeLegacyChangeEvent(data json.RawMessage) (map[string]Value, error)

DecodeLegacyChangeEvent decodes a JSON encoded RES-service v1.0 model change event

func EncodeAddEvent

func EncodeAddEvent(d *AddEvent) json.RawMessage

EncodeAddEvent creates a JSON encoded RES-service collection add event

func EncodeChangeEvent added in v1.2.0

func EncodeChangeEvent(values map[string]Value) json.RawMessage

EncodeChangeEvent creates a JSON encoded RES-service change event

func EncodeRemoveEvent

func EncodeRemoveEvent(d *RemoveEvent) json.RawMessage

EncodeRemoveEvent creates a JSON encoded RES-service collection remove event

func IsLegacyChangeEvent added in v1.2.0

func IsLegacyChangeEvent(data json.RawMessage) bool

IsLegacyChangeEvent returns true if the model change event is detected as v1.0 legacy [DEPRECATED:deprecatedModelChangeEvent]

func IsValidRID

func IsValidRID(rid string, allowQuery bool) bool

IsValidRID returns true if the RID is valid, otherwise false. If allowQuery flag is false, encountering a question mark (?) will cause IsValidRID to return false.

func IsValidRIDPart added in v1.5.0

func IsValidRIDPart(part string) bool

IsValidRIDPart returns true if the RID part is valid, otherwise false.

func MergeHeader added in v1.8.0

func MergeHeader(a, b http.Header)

MergeHeader adds or replaces headers in a with the headers in b. It does not included protected headers, and it appends header values for "Set-Cookie".

func TryDecodeLegacyNewResult added in v1.4.0

func TryDecodeLegacyNewResult(result json.RawMessage) (string, error)

TryDecodeLegacyNewResult tries to detect legacy v1.1.1 behavior. Returns empty string and nil error when the result is not detected as legacy. [DEPRECATED:deprecatedNewCallRequest]

Types

type AccessResponse

type AccessResponse struct {
	Result *AccessResult `json:"result"`
	Error  *reserr.Error `json:"error"`
	Meta   *Meta         `json:"meta"`
}

AccessResponse represents the response of a RES-service access request https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#access-request

type AccessResult

type AccessResult struct {
	Get  bool   `json:"get"`
	Call string `json:"call"`
}

AccessResult represents the response result of a RES-service access request

type AddEvent

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

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

func DecodeAddEvent

func DecodeAddEvent(data json.RawMessage) (*AddEvent, error)

DecodeAddEvent decodes a JSON encoded RES-service collection add event

type AuthRequest

type AuthRequest struct {
	Request
	Header     http.Header `json:"header,omitempty"`
	Host       string      `json:"host,omitempty"`
	RemoteAddr string      `json:"remoteAddr,omitempty"`
	URI        string      `json:"uri,omitempty"`
}

AuthRequest represents a RES-service auth request https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#auth-request

type AuthRequester

type AuthRequester interface {
	// CID returns the connection of the requester
	CID() string
	// HTTPRequest returns the http.Request from requesters (upgraded) HTTP connection
	HTTPRequest() *http.Request
}

AuthRequester is the connection making the auth request

type ChangeEvent added in v1.2.0

type ChangeEvent struct {
	Values map[string]Value `json:"values"`
}

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

type ConnTokenEvent

type ConnTokenEvent struct {
	Token json.RawMessage `json:"token"`
	TID   string          `json:"tid"`
}

ConnTokenEvent represents a RES-server connection token event https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#connection-token-event

func DecodeConnTokenEvent

func DecodeConnTokenEvent(payload []byte) (*ConnTokenEvent, error)

DecodeConnTokenEvent decodes a JSON encoded RES-service connection token event

type EventQueryEvent

type EventQueryEvent struct {
	Event string          `json:"event"`
	Data  json.RawMessage `json:"data"`
}

EventQueryEvent represents an event in the response of a RES-server query request

type EventQueryRequest

type EventQueryRequest struct {
	Query string `json:"query"`
}

EventQueryRequest represents a RES-service query request https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#query-request

type EventQueryResponse

type EventQueryResponse struct {
	Result *EventQueryResult `json:"result"`
	Error  *reserr.Error     `json:"error"`
}

EventQueryResponse represent the response of a RES-service query request https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#query-event

type EventQueryResult

type EventQueryResult struct {
	Events     []*EventQueryEvent `json:"events"`
	Model      map[string]Value   `json:"model"`
	Collection []Value            `json:"collection"`
}

EventQueryResult represent the response's result part of a RES-service query request

func DecodeEventQueryResponse

func DecodeEventQueryResponse(payload []byte) (*EventQueryResult, error)

DecodeEventQueryResponse decodes a JSON encoded RES-service event query response

type GetRequest

type GetRequest struct {
	Query string `json:"query,omitempty"`
}

GetRequest represents a RES-service get request https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#get-request

type GetResponse

type GetResponse struct {
	Result *GetResult    `json:"result"`
	Error  *reserr.Error `json:"error"`
}

GetResponse represents the response of a RES-service get request

type GetResult

type GetResult struct {
	Model      map[string]Value `json:"model"`
	Collection []Value          `json:"collection"`
	Query      string           `json:"query"`
}

GetResult represent the response result of a RES-service get request

func DecodeGetResponse

func DecodeGetResponse(payload []byte) (*GetResult, error)

DecodeGetResponse decodes a JSON encoded RES-service get response

type Meta added in v1.8.0

type Meta struct {
	Status *int        `json:"status"`
	Header http.Header `json:"header"`
}

Meta represents the meta object of a response https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#meta-object

func DecodeCallResponse

func DecodeCallResponse(payload []byte) (json.RawMessage, string, *Meta, error)

DecodeCallResponse decodes a JSON encoded RES-service call response

func (*Meta) Canonicalize added in v1.8.0

func (m *Meta) Canonicalize()

Canonicalize updates the header keys to be in the canonicalized format.

func (*Meta) GetHeader added in v1.8.0

func (m *Meta) GetHeader() http.Header

func (*Meta) IsDirectResponseStatus added in v1.8.0

func (m *Meta) IsDirectResponseStatus() bool

IsDirectResponseStatus returns true if the status code should not result in any subsequent request, but should be directly responded to. https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#status-codes

func (*Meta) IsValidStatus added in v1.8.0

func (m *Meta) IsValidStatus() bool

IsValidStatus returns true if the meta status code is valid while establishing HTTP or WebSocket connections. https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#status-codes

func (*Meta) Merge added in v1.8.0

func (m *Meta) Merge(o *Meta) *Meta

Merge merges with another meta object. If m is nil, o is returned. If o is nil, m is returned. If both o and m are not nil, the values are merged so that values in m are appended or replaced with values in o.

type NewResponse

type NewResponse struct {
	Result *Resource     `json:"result"`
	Error  *reserr.Error `json:"error"`
}

NewResponse represents the response of a RES-service new call request https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#new-call-request

type QueryEvent

type QueryEvent struct {
	Subject string `json:"subject"`
}

QueryEvent represents a RES-service query event

func DecodeQueryEvent

func DecodeQueryEvent(payload []byte) (*QueryEvent, error)

DecodeQueryEvent decodes a JSON encoded query event

type RemoveEvent

type RemoveEvent struct {
	Idx int `json:"idx"`
}

RemoveEvent represent a RES-server collection remove event https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#collection-remove-event

func DecodeRemoveEvent

func DecodeRemoveEvent(data json.RawMessage) (*RemoveEvent, error)

DecodeRemoveEvent decodes a JSON encoded RES-service collection remove event

type Request

type Request struct {
	Params interface{} `json:"params,omitempty"`
	Token  interface{} `json:"token,omitempty"`
	Query  string      `json:"query,omitempty"`
	CID    string      `json:"cid"`
	IsHTTP bool        `json:"isHttp,omitempty"`
}

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

type Requester

type Requester interface {
	// CID returns the connection of the requester
	CID() string
}

Requester is the connection making the request

type Resource added in v1.4.0

type Resource struct {
	RID string `json:"rid"`
}

Resource represents the resource response of a RES-service call or auth request

type Response

type Response struct {
	Result   json.RawMessage `json:"result"`
	Resource *Resource       `json:"resource"`
	Error    *reserr.Error   `json:"error"`
	Meta     *Meta           `json:"meta"`
}

Response represents a RES-service response https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#response

type SystemReset

type SystemReset struct {
	Resources []string `json:"resources"`
	Access    []string `json:"access"`
}

SystemReset represents a RES-server system reset event https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#system-reset-event

func DecodeSystemReset

func DecodeSystemReset(data json.RawMessage) (SystemReset, error)

DecodeSystemReset decodes a JSON encoded RES-service system reset event

type SystemTokenReset added in v1.7.0

type SystemTokenReset struct {
	TIDs    []string `json:"tids"`
	Subject string   `json:"subject"`
}

SystemTokenReset represents a RES-server system token reset event https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#system-token-reset-event

func DecodeSystemTokenReset added in v1.7.0

func DecodeSystemTokenReset(data json.RawMessage) (SystemTokenReset, error)

DecodeSystemTokenReset decodes a JSON encoded RES-service system token reset event

type Value

type Value struct {
	json.RawMessage
	Type  ValueType
	RID   string
	Inner json.RawMessage
}

Value represents a RES value https://github.com/resgateio/resgate/blob/master/docs/res-protocol.md#values

func (Value) Equal

func (v Value) Equal(w Value) bool

Equal reports whether v and w is equal in type and value

func (Value) IsProper added in v1.6.0

func (v Value) IsProper() bool

IsProper returns true if the value's type is either a primitive, a reference, or a data value.

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *v to the RES value represented by the JSON encoded data

type ValueObject

type ValueObject struct {
	RID    *string         `json:"rid"`
	Soft   bool            `json:"soft"`
	Action *string         `json:"action"`
	Data   json.RawMessage `json:"data"`
}

ValueObject represents a resource reference or an action

type ValueType

type ValueType byte

ValueType is an enum reprenting the value type

const (
	ValueTypeNone ValueType = iota
	ValueTypeDelete
	ValueTypePrimitive
	ValueTypeReference
	ValueTypeSoftReference
	ValueTypeData
)

Value type constants

Jump to

Keyboard shortcuts

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