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的节点通过判定 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")
Functions ¶
func IsInnerTopic ¶
func IsPublicTopic ¶
func IsSysTopic ¶
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 MsgType ¶ added in v0.2.2
type MsgType string
type Serializer ¶
type Serializer struct {
// contains filtered or unexported fields
}
func NewSerializer ¶
func NewSerializer(messagePrefix []byte) *Serializer
func (*Serializer) Deserialize ¶
func (ms *Serializer) Deserialize(t Topic, 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.
func (*Serializer) GetMsgTopic ¶
func (ms *Serializer) GetMsgTopic(websocketMessage []byte) Topic
getWebsocketCustomEvent return empty string when the websocketMessage is native message
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.
Click to show internal directories.
Click to hide internal directories.