message

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PublicTopic = ""
	// 用户保留主题 不会进行广播
	InnerTopic = "inner"
	// 系统保留主题 不会触发任何注册的回调函数
	SysTopic = "sys"
)

Variables

View Source
var (
	// 订阅指令
	TopicSubscribe = NewTopic("/sys/subscribe")
	// 取消订阅指令
	TopicCancel = NewTopic("/sys/cancel")
	// 取消所有订阅指令
	TopicCancelAll = NewTopic("/sys/cancel_all")
	// 敏感操作 仅来自127.0.0.1的节点通过判定
	TopicSubscribeAll = NewTopic("/sys/admin/subscribe_all")
	TopicGetAllTopics = NewTopic("/sys/admin/get_all_topics")
	TopicGetAllNodes  = NewTopic("/sys/admin/get_all_nodes")
	TopicStopNode     = NewTopic("/sys/admin/stop_node")

	// 日志
	TopicSysLog = NewTopic("/sys/log")
	// 连接权限验证
	TopicAuth = NewTopic("/sys/auth")
)
View Source
var (
	ErrNotAllowedTopic = errors.New("this topic is not allowed to subscribe or publish")
	ErrUnformedMsg     = errors.New("unformed Msg")
)
View Source
var InvalidMessage = errors.New("invalid message")
View Source
var InvalidPrefix = errors.New("invalid prefix")
View Source
var InvalidTopic = errors.New("invalid topic")

Functions

func IsInnerTopic

func IsInnerTopic(t Topic) bool

func IsPublicTopic

func IsPublicTopic(t Topic) bool

func IsSysTopic

func IsSysTopic(t Topic) bool

func MsgTypeName added in v0.2.3

func MsgTypeName(m MsgType) string

func TypeofTopic

func TypeofTopic(t Topic) string

Types

type Func added in v0.2.2

type Func interface{}

A callback which should receives one parameter of type string, int, bool or any valid JSON/Go struct

type FuncBlank added in v0.2.2

type FuncBlank = func()

type FuncBool added in v0.2.2

type FuncBool = func(bool)

type FuncBytes added in v0.2.2

type FuncBytes = func([]byte)

type FuncDefault added in v0.2.2

type FuncDefault = func(interface{})

type FuncInt added in v0.2.2

type FuncInt = func(int)

type FuncString added in v0.2.2

type FuncString = func(string)

type FuncTransfer added in v0.2.3

type FuncTransfer = func([]byte, string, string)

type MsgType added in v0.2.2

type MsgType = byte
const (
	MsgTypeString MsgType = '0'
	MsgTypeInt    MsgType = '1'
	MsgTypeBool   MsgType = '2'
	MsgTypeBytes  MsgType = '3'
	MsgTypeJSON   MsgType = '4'
)

The same values are exists on client side too.

type Serializer

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

func NewSerializer

func NewSerializer(messagePrefix []byte) *Serializer

func (*Serializer) AddSourceTopicItem added in v0.2.3

func (ms *Serializer) AddSourceTopicItem(msg []byte, source_id string)

func (*Serializer) Deserialize

func (ms *Serializer) Deserialize(websocketMessage []byte) (interface{}, MsgType, error)

deserialize deserializes a custom websocket message from the client such as prefix;topic;0;abc_msg Supported data types are: string, int, bool, bytes and JSON. 格式: prefix;target_topic;source_topic;random_tag;type;msg

func (*Serializer) GetMsgTopic

func (ms *Serializer) GetMsgTopic(websocketMessage []byte) Topic

getWebsocketCustomEvent return empty string when the websocketMessage is native message 格式: prefix;target_topic;source_topic;random_tag;type;msg

func (*Serializer) GetSourceTopic added in v0.2.3

func (ms *Serializer) GetSourceTopic(msg []byte) Topic

func (*Serializer) SeparateMessage added in v0.2.3

func (ms *Serializer) SeparateMessage(msg []byte) (target Topic, source Topic, tag string, typ MsgType, data []byte)

func (*Serializer) Serialize

func (ms *Serializer) Serialize(t Topic, data interface{}) ([]byte, error)

websocketMessageSerialize serializes a custom websocket message from websocketServer to be delivered to the client returns the string form of the message Supported data types are: string, int, bool, bytes and JSON. 格式: prefix;target_topic;source_topic;random_tag;type;msg

type Topic

type Topic interface {
	String() string
	FirstFragment() string
	Fragment(int) string
	Since(int) string
	Len() int
}

func NewTopic

func NewTopic(t string) Topic

Jump to

Keyboard shortcuts

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