Documentation ¶
Overview ¶
Package common contains struts and interfaces shared between multiple components
Index ¶
- Constants
- func ActionCableExtendedProtocols() []string
- func ActionCableProtocols() []string
- func ConfirmationMessage(identifier string) string
- func DisconnectionMessage(reason string, reconnect bool) string
- func IsExtendedActionCableProtocol(protocol string) bool
- func PubSubMessageFromJSON(raw []byte) (interface{}, error)
- func RejectionMessage(identifier string) string
- func StatusName(status int) string
- func WelcomeMessage(sid string) string
- type CallResult
- type CommandResult
- type ConnectResult
- type DisconnectMessage
- type HistoryPosition
- type HistoryRequest
- type Message
- type PingMessage
- type RemoteCommandMessage
- type RemoteDisconnectMessage
- type Reply
- type SessionEnv
- func (st *SessionEnv) GetChannelStateField(id string, field string) string
- func (st *SessionEnv) GetConnectionStateField(field string) string
- func (st *SessionEnv) MergeChannelState(id string, other *map[string]string)
- func (st *SessionEnv) MergeConnectionState(other *map[string]string)
- func (st *SessionEnv) RemoveChannelState(id string)
- func (st *SessionEnv) SetHeader(key string, val string)
- type StreamMessage
- type StreamMessageMetadata
Constants ¶
const ( SUCCESS = iota FAILURE ERROR )
Command result status
const ( ActionCableV1JSON = "actioncable-v1-json" ActionCableV1ExtJSON = "actioncable-v1-ext-json" )
const ( WelcomeType = "welcome" PingType = "ping" DisconnectType = "disconnect" ConfirmedType = "confirm_subscription" RejectedType = "reject_subscription" // Not supported by Action Cable currently UnsubscribedType = "unsubscribed" HistoryConfirmedType = "confirm_history" HistoryRejectedType = "reject_history" WhisperType = "whisper" )
Outgoing message types (according to Action Cable protocol)
const ( SERVER_RESTART_REASON = "server_restart" REMOTE_DISCONNECT_REASON = "remote" IDLE_TIMEOUT_REASON = "idle_timeout" NO_PONG_REASON = "no_pong" UNAUTHORIZED_REASON = "unauthorized" )
Disconnect reasons
const (
WHISPER_STREAM_STATE = "$w"
)
Reserver state fields
Variables ¶
This section is empty.
Functions ¶
func ActionCableExtendedProtocols ¶ added in v1.4.3
func ActionCableExtendedProtocols() []string
func ActionCableProtocols ¶ added in v1.2.2
func ActionCableProtocols() []string
func ConfirmationMessage ¶ added in v1.2.0
ConfirmationMessage returns a subscription confirmation message for a specified identifier
func DisconnectionMessage ¶ added in v1.5.0
DisconnectionMessage returns a disconnect message with the specified reason and reconnect flag
func IsExtendedActionCableProtocol ¶ added in v1.4.3
func PubSubMessageFromJSON ¶
PubSubMessageFromJSON takes raw JSON byte array and return the corresponding struct
func RejectionMessage ¶ added in v1.2.0
RejectionMessage returns a subscription rejection message for a specified identifier
func StatusName ¶ added in v1.5.0
func WelcomeMessage ¶ added in v1.5.0
WelcomeMessage for a session ID
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 DisconnectInterest int 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) LogValue ¶ added in v1.5.0
func (c *CommandResult) LogValue() slog.Value
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 DisconnectInterest int Status int }
ConnectResult is a result of initializing a connection (calling a Connect method)
func (*ConnectResult) LogValue ¶ added in v1.5.0
func (c *ConnectResult) LogValue() slog.Value
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 NewDisconnectMessage ¶ added in v1.2.3
func NewDisconnectMessage(reason string, reconnect bool) *DisconnectMessage
func (*DisconnectMessage) GetType ¶ added in v1.1.0
func (d *DisconnectMessage) GetType() string
func (*DisconnectMessage) LogValue ¶ added in v1.5.0
func (d *DisconnectMessage) LogValue() slog.Value
type HistoryPosition ¶ added in v1.4.0
func (*HistoryPosition) LogValue ¶ added in v1.5.0
func (hp *HistoryPosition) LogValue() slog.Value
type HistoryRequest ¶ added in v1.4.0
type HistoryRequest struct { // Since is UTC timestamp in ms Since int64 `json:"since,omitempty"` // Streams contains the information of last offsets/epoch received for a particular stream Streams map[string]HistoryPosition `json:"streams,omitempty"` }
HistoryRequest represents a client's streams state (offsets) or a timestamp since which we should return the messages for the current streams
func (*HistoryRequest) LogValue ¶ added in v1.5.0
func (hr *HistoryRequest) LogValue() slog.Value
type Message ¶
type Message struct { Command string `json:"command"` Identifier string `json:"identifier"` Data interface{} `json:"data,omitempty"` History HistoryRequest `json:"history,omitempty"` }
Message represents incoming client message
type PingMessage ¶ added in v1.0.3
type PingMessage struct { Type string `json:"type"` Message interface{} `json:"message,omitempty"` }
PingMessage represents a server ping
func (*PingMessage) GetType ¶ added in v1.1.0
func (p *PingMessage) GetType() string
func (*PingMessage) LogValue ¶ added in v1.5.0
func (p *PingMessage) LogValue() slog.Value
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)
func (*RemoteCommandMessage) LogValue ¶ added in v1.5.0
func (m *RemoteCommandMessage) LogValue() slog.Value
func (*RemoteCommandMessage) ToRemoteDisconnectMessage ¶ added in v1.4.0
func (m *RemoteCommandMessage) ToRemoteDisconnectMessage() (*RemoteDisconnectMessage, error)
type RemoteDisconnectMessage ¶
type RemoteDisconnectMessage struct { Identifier string `json:"identifier"` Reconnect bool `json:"reconnect"` }
RemoteDisconnectMessage contains information required to disconnect a session
func (*RemoteDisconnectMessage) LogValue ¶ added in v1.5.0
func (m *RemoteDisconnectMessage) LogValue() slog.Value
type Reply ¶ added in v1.0.3
type Reply struct { Type string `json:"type,omitempty"` Identifier string `json:"identifier,omitempty"` Message interface{} `json:"message,omitempty"` Reason string `json:"reason,omitempty"` Reconnect bool `json:"reconnect,omitempty"` StreamID string `json:"stream_id,omitempty"` Epoch string `json:"epoch,omitempty"` Offset uint64 `json:"offset,omitempty"` Sid string `json:"sid,omitempty"` Restored bool `json:"restored,omitempty"` RestoredIDs []string `json:"restored_ids,omitempty"` }
Reply represents an outgoing client message
type SessionEnv ¶
type SessionEnv struct { URL string Headers *map[string]string Identifiers string ConnectionState *map[string]string ChannelStates *map[string]map[string]string }
SessionEnv represents the underlying HTTP connection data: URL and request headers. It also carries channel and connection state information used by the RPC app.
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) RemoveChannelState ¶ added in v1.5.0
func (st *SessionEnv) RemoveChannelState(id string)
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"` Meta *StreamMessageMetadata `json:"meta,omitempty"` // Offset is the position of this message in the stream Offset uint64 // Epoch is the uniq ID of the current storage state Epoch string }
StreamMessage represents a pub/sub message to be sent to stream
func (*StreamMessage) LogValue ¶ added in v1.5.0
func (sm *StreamMessage) LogValue() slog.Value
func (*StreamMessage) ToReplyFor ¶ added in v1.2.3
func (sm *StreamMessage) ToReplyFor(identifier string) *Reply
type StreamMessageMetadata ¶ added in v1.4.5
type StreamMessageMetadata struct { ExcludeSocket string `json:"exclude_socket,omitempty"` // BroadcastType defines the message type to be used for messages sent to clients BroadcastType string `json:"broadcast_type,omitempty"` // Transient defines whether this message should be stored in the history Transient bool `json:"transient,omitempty"` }
StreamMessageMetadata describes additional information about a stream message which can be used to modify delivery behavior
func (*StreamMessageMetadata) LogValue ¶ added in v1.5.0
func (smm *StreamMessageMetadata) LogValue() slog.Value