Documentation
¶
Index ¶
- Constants
- Variables
- func IsInnerTopic(t Topic) bool
- func IsPublicTopic(t Topic) bool
- func IsSysTopic(t Topic) bool
- func MsgTypeName(m MsgType) string
- func TypeofTopic(t Topic) string
- type Func
- type FuncBlank
- type FuncBool
- type FuncBytes
- type FuncDefault
- type FuncError
- type FuncInt
- type FuncString
- type FuncTransfer
- type MsgType
- type Publisher
- type Serializer
- func (ms *Serializer) Deserialize(websocketMessage []byte) (interface{}, error)
- func (ms *Serializer) GetMsgTopic(websocketMessage []byte) Topic
- func (ms *Serializer) GetMsgType(msg []byte) MsgType
- func (ms *Serializer) GetRandomID(msg []byte) uint32
- func (ms *Serializer) GetSourceID(msg []byte) uint32
- func (ms *Serializer) ResetRandomTag(msg []byte, randomTag int)
- func (ms *Serializer) ResetSourceID(msg []byte, sourceId int)
- func (ms *Serializer) ReturnBackBytes(p []byte)
- func (ms *Serializer) Serialize(t Topic, data interface{}) ([]byte, error)
- type Subscriber
- type SubscriberList
- type Topic
Constants ¶
View Source
const ( PublicTopic = "" // 用户保留主题 不会进行广播 InnerTopic = "inner" // 系统保留主题 不会触发任何注册的回调函数 SysTopic = "sys" )
Variables ¶
View Source
var ( // 日志 TopicSysLog = NewTopic("/sys/log") // 连接权限验证 TopicAuth = NewTopic("/sys/auth") // 订阅指令 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") // 共享集群信息 TopicClusterIps = NewTopic("/sys/cluster/ips") // 声明自己是个同级节点 同时声明自己的id TopicLateral = NewTopic("/sys/cluster/lateral") TopicLateralRedirect = NewTopic("/sys/cluster/lateral/redirect") // 声明自己是个子级节点 TopicSuperior = NewTopic("/sys/cluster/Superior") // 同步 父级可连接地址 TopicSuperiorIps = NewTopic("/sys/cluster/Superior/ips") )
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 InvalidTopic = errors.New("invalid topic")
Functions ¶
func IsInnerTopic ¶
func IsPublicTopic ¶
func IsSysTopic ¶
func MsgTypeName ¶ added in v0.2.3
func TypeofTopic ¶
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 FuncDefault ¶ added in v0.2.2
type FuncDefault = func(interface{})
type FuncString ¶ added in v0.2.2
type FuncString = func(string)
type FuncTransfer ¶ added in v0.2.3
type Publisher ¶ added in v0.2.4
type Publisher interface {
// Pub sends a message on a particular topic
Pub(interface{})
}
Publisher is the message manager
type Serializer ¶
type Serializer struct {
// contains filtered or unexported fields
}
func NewSerializer ¶
func NewSerializer(messagePrefix []byte) *Serializer
格式: prefix(n)type(1)random_tag(4)source_idx(4)target_topic;msg
func (*Serializer) Deserialize ¶
func (ms *Serializer) Deserialize(websocketMessage []byte) (interface{}, 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(n)type(1)random_tag(4)source_idx(4)target_topic;msg
func (*Serializer) GetMsgTopic ¶
func (ms *Serializer) GetMsgTopic(websocketMessage []byte) Topic
getWebsocketCustomEvent return empty string when the websocketMessage is native message 格式: prefix(n)type(1)random_tag(4)source_idx(4)target_topic;msg
func (*Serializer) GetMsgType ¶ added in v0.2.4
func (ms *Serializer) GetMsgType(msg []byte) MsgType
func (*Serializer) GetRandomID ¶ added in v0.2.4
func (ms *Serializer) GetRandomID(msg []byte) uint32
func (*Serializer) GetSourceID ¶ added in v0.2.4
func (ms *Serializer) GetSourceID(msg []byte) uint32
格式: prefix(n)type(1)random_tag(4)source_idx(4)target_topic;msg
func (*Serializer) ResetRandomTag ¶ added in v0.2.4
func (ms *Serializer) ResetRandomTag(msg []byte, randomTag int)
func (*Serializer) ResetSourceID ¶ added in v0.2.4
func (ms *Serializer) ResetSourceID(msg []byte, sourceId int)
func (*Serializer) ReturnBackBytes ¶ added in v0.2.4
func (ms *Serializer) ReturnBackBytes(p []byte)
type Subscriber ¶ added in v0.2.4
type SubscriberList ¶ added in v0.2.4
type SubscriberList interface {
Add(callback Func) Subscriber
Range(func(s Subscriber))
Len() int
}
func NewSubscriberList ¶ added in v0.2.4
func NewSubscriberList() SubscriberList
Click to show internal directories.
Click to hide internal directories.