Help us shape the future of Go! Take the 2026 Go Developer Survey

common

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 2 Imported by: 18

Documentation

Overview

Package common contains struts and interfaces shared between multiple components

Index

Constants

View Source
const (
	SUCCESS = iota
	FAILURE
	ERROR
)

Command result status

View Source
const (
	WelcomeType    = "welcome"
	PingType       = "ping"
	ReplyType      = "message"
	DisconnectType = "disconnect"
	ConfirmedType  = "confirm_subscription"
	RejectedType   = "reject_subscription"
	// Not suppurted by Action Cable currently
	UnsubscribedType = "unsubscribed"
)

Outgoing message types (according to Action Cable protocol)

View Source
const (
	ActionCableV1JSON = "actioncable-v1-json"
)

Variables

This section is empty.

Functions

func ActionCableProtocols added in v1.2.2

func ActionCableProtocols() []string

func ConfirmationMessage added in v1.2.0

func ConfirmationMessage(identifier string) string

ConfirmationMessage returns a subscription confirmation message for a specified identifier

func PubSubMessageFromJSON

func PubSubMessageFromJSON(raw []byte) (interface{}, error)

PubSubMessageFromJSON takes raw JSON byte array and return the corresponding struct

func RejectionMessage added in v1.2.0

func RejectionMessage(identifier string) string

RejectionMessage returns a subscription rejection message for a specified identifier

Types

type CallResult

type CallResult struct {
	Transmissions []string
	Broadcasts    []*StreamMessage
	CState        map[string]string
	IState        map[string]string
}

CallResult contains shared RPC result fields

type CommandResult

type CommandResult struct {
	StopAllStreams bool
	Disconnect     bool
	Streams        []string
	StoppedStreams []string
	Transmissions  []string
	Broadcasts     []*StreamMessage
	CState         map[string]string
	IState         map[string]string
	Status         int
}

CommandResult is a result of performing controller action, which contains informations about streams to subscribe, messages to sent and broadcast. It's a communication "protocol" between a node and a controller.

func (*CommandResult) ToCallResult

func (c *CommandResult) ToCallResult() *CallResult

ToCallResult returns the corresponding CallResult

type ConnectResult

type ConnectResult struct {
	Identifier    string
	Transmissions []string
	Broadcasts    []*StreamMessage
	CState        map[string]string
	IState        map[string]string
	Status        int
}

ConnectResult is a result of initializing a connection (calling a Connect method)

func (*ConnectResult) ToCallResult

func (c *ConnectResult) ToCallResult() *CallResult

ToCallResult returns the corresponding CallResult

type DisconnectMessage added in v1.0.3

type DisconnectMessage struct {
	Type      string `json:"type"`
	Reason    string `json:"reason"`
	Reconnect bool   `json:"reconnect"`
}

DisconnectMessage represents a server disconnect message

func (*DisconnectMessage) GetType added in v1.1.0

func (d *DisconnectMessage) GetType() string

type Message

type Message struct {
	Command    string      `json:"command"`
	Identifier string      `json:"identifier"`
	Data       interface{} `json:"data"`
}

Message represents incoming client message

type PingMessage added in v1.0.3

type PingMessage struct {
	Type    string      `json:"type"`
	Message interface{} `json:"message"`
}

PingMessage represents a server ping

func (*PingMessage) GetType added in v1.1.0

func (p *PingMessage) GetType() string

type RemoteCommandMessage

type RemoteCommandMessage struct {
	Command string          `json:"command,omitempty"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

RemoteCommandMessage represents a pub/sub message with a remote command (e.g., disconnect)

type RemoteDisconnectMessage

type RemoteDisconnectMessage struct {
	Identifier string `json:"identifier"`
	Reconnect  bool   `json:"reconnect"`
}

RemoteDisconnectMessage contains information required to disconnect a session

type Reply added in v1.0.3

type Reply struct {
	Type       string      `json:"type,omitempty"`
	Identifier string      `json:"identifier"`
	Message    interface{} `json:"message,omitempty"`
}

Reply represents an outgoing client message

func (*Reply) GetType added in v1.1.0

func (r *Reply) GetType() string

type SessionEnv

type SessionEnv struct {
	URL             string
	Headers         *map[string]string
	ConnectionState *map[string]string
	ChannelStates   *map[string]map[string]string
}

SessionEnv represents the underlying HTTP connection data: URL and request headers

func NewSessionEnv

func NewSessionEnv(url string, headers *map[string]string) *SessionEnv

NewSessionEnv builds a new SessionEnv

func (*SessionEnv) GetChannelStateField added in v1.1.4

func (st *SessionEnv) GetChannelStateField(id string, field string) string

Returns a value for the specified key of the specified channel

func (*SessionEnv) GetConnectionStateField added in v1.1.4

func (st *SessionEnv) GetConnectionStateField(field string) string

Returns a value for the specified connection state field

func (*SessionEnv) MergeChannelState

func (st *SessionEnv) MergeChannelState(id string, other *map[string]string)

MergeChannelState updates the current ChannelStates for the given identifier. If the value is an empty string then remove the key, otherswise add or rewrite.

func (*SessionEnv) MergeConnectionState

func (st *SessionEnv) MergeConnectionState(other *map[string]string)

MergeConnectionState updates the current ConnectionState from the given map. If the value is an empty string then remove the key, otherswise add or rewrite.

func (*SessionEnv) SetHeader added in v1.1.2

func (st *SessionEnv) SetHeader(key string, val string)

SetHeader adds a header to the headers list

type StreamMessage

type StreamMessage struct {
	Stream string `json:"stream"`
	Data   string `json:"data"`
}

StreamMessage represents a pub/sub message to be sent to stream

Jump to

Keyboard shortcuts

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