Documentation ¶
Overview ¶
Package pushKit 此文件中的几个方法,需要在子类中实现!
Index ¶
- Variables
- func BindBsid(channel Channel, bsid string)
- func BindGroup(channel Channel, group string)
- func BindId(channel Channel, id string)
- func BindUser(channel Channel, user string)
- func CheckSetup() error
- func CloseAll(reason string)
- func CloseByBsid(bsid string, reason string) (err error)
- func CloseByGroup(group string, reason string)
- func CloseById(id string, reason string) (err error)
- func CloseByUser(user string, reason string)
- func DefaultIdGenerator() func() (string, error)
- func GetCountOfBsidMap() int
- func GetCountOfGroupMap() (count int)
- func GetCountOfIdMap() int
- func GetCountOfUserMap() (count int)
- func GetDefaultLogger() *logrus.Logger
- func GetStatistics() string
- func IsNoSuitableChannelError(err error) bool
- func MustSetUp(antPool *ants.Pool, logger *logrus.Logger)
- func PushToAll(data []byte, exceptBsids []string) (err error)
- func PushToBsid(data []byte, bsid string) (err error)
- func PushToGroup(data []byte, group string, exceptBsids []string) (err error)
- func PushToUser(data []byte, user string, exceptBsids []string) (err error)
- func SetDefaultLogger(logrusLogger *logrus.Logger) error
- func Setup(antPool *ants.Pool, logger *logrus.Logger) (err error)
- func UnbindBsid(channel Channel)
- func UnbindGroup(channel Channel)
- func UnbindId(channel Channel)
- func UnbindUser(channel Channel)
- type BaseChannel
- func (channel *BaseChannel) BindBsid(bsid string)
- func (channel *BaseChannel) BindGroup(group string)
- func (channel *BaseChannel) BindUser(user string)
- func (channel *BaseChannel) ClearBsid()
- func (channel *BaseChannel) ClearData()
- func (channel *BaseChannel) ClearGroup()
- func (channel *BaseChannel) ClearUser()
- func (channel *BaseChannel) Close(reason string) error
- func (channel *BaseChannel) Dispose()
- func (channel *BaseChannel) Equals(c Channel) bool
- func (channel *BaseChannel) GetBsid() (bsid string)
- func (channel *BaseChannel) GetClientIP() string
- func (channel *BaseChannel) GetCloseCh() chan string
- func (channel *BaseChannel) GetData() (data interface{})
- func (channel *BaseChannel) GetGroup() (group string)
- func (channel *BaseChannel) GetId() (id string)
- func (channel *BaseChannel) GetType() string
- func (channel *BaseChannel) GetUser() (user string)
- func (channel *BaseChannel) Initialize() error
- func (channel *BaseChannel) IsClosed() (rst bool)
- func (channel *BaseChannel) Push(data []byte) error
- func (channel *BaseChannel) SetBsid(bsid string)
- func (channel *BaseChannel) SetClosed() (flag bool)
- func (channel *BaseChannel) SetData(data interface{})
- func (channel *BaseChannel) SetGroup(group string)
- func (channel *BaseChannel) SetUser(user string)
- type Channel
- type Listener
- type Listeners
- func (listeners Listeners) BeforeClosedByBackend(channel Channel, closeInfo string)
- func (listeners Listeners) OnClose(channel Channel, closeInfo string)
- func (listeners Listeners) OnFailure(w http.ResponseWriter, r *http.Request, failureInfo string)
- func (listeners Listeners) OnHandshake(w http.ResponseWriter, r *http.Request, channel Channel)
- func (listeners Listeners) OnMessage(channel Channel, messageType int, data []byte)
- type Processor
Constants ¶
This section is empty.
Variables ¶
var ( PingData = []byte("ping") PongData = []byte("pong") )
Functions ¶
func CheckSetup ¶ added in v3.0.38
func CheckSetup() error
func DefaultIdGenerator ¶
func GetCountOfBsidMap ¶
func GetCountOfBsidMap() int
func GetCountOfGroupMap ¶
func GetCountOfGroupMap() (count int)
func GetCountOfIdMap ¶
func GetCountOfIdMap() int
func GetCountOfUserMap ¶
func GetCountOfUserMap() (count int)
func GetDefaultLogger ¶
func GetStatistics ¶
func GetStatistics() string
GetStatistics
e.g. +----------+-------------------+ | TYPE | COUNT OF CHANNELS | +----------+-------------------+ | idMap | 0 | | bsidMap | 0 | | userMap | 0 | | groupMap | 0 | +----------+-------------------+
func IsNoSuitableChannelError ¶ added in v3.0.52
IsNoSuitableChannelError 推送返回的error,是否是因为不存在对应的channel?
func PushToBsid ¶
func SetDefaultLogger ¶
func Setup ¶
Setup
@param antPool 用来并发执行推送任务
(1) 不能为nil (2) 需要自行决定: cap大小、是否自定义输出...
@param logger 可以为nil @param options
func UnbindGroup ¶
func UnbindGroup(channel Channel)
UnbindGroup
PS: (1) 仅是解绑,不会关闭channel; (2) 解绑成功后,如果set为空,应该移除掉.
func UnbindUser ¶
func UnbindUser(channel Channel)
UnbindUser
PS: (1) 仅是解绑,不会关闭channel; (2) 解绑成功后,如果set为空,应该移除掉.
Types ¶
type BaseChannel ¶
type BaseChannel struct { mutexKit.RWMutex CloseCh chan string // ClientIP 可能是error string(获取失败的情况下). ClientIP string // Type Channel 的类型. Type string Id string Bsid string User string Group string Data interface{} Closed bool Listeners Listeners PongInterval time.Duration Interval *timeKit.Interval }
BaseChannel
!!!: (1) 此类型实现了部分 Channel 接口, (2) 此类型的子类应当实现 Channel 接口(主要是: Push()、Close()、bind、unbind),不能覆盖父类的方法.
(由于unbind可能涉及Close(),因此只能在子类中实现)
func (*BaseChannel) BindBsid ¶ added in v3.0.59
func (channel *BaseChannel) BindBsid(bsid string)
func (*BaseChannel) BindGroup ¶ added in v3.0.59
func (channel *BaseChannel) BindGroup(group string)
func (*BaseChannel) BindUser ¶ added in v3.0.59
func (channel *BaseChannel) BindUser(user string)
func (*BaseChannel) ClearBsid ¶
func (channel *BaseChannel) ClearBsid()
func (*BaseChannel) ClearData ¶
func (channel *BaseChannel) ClearData()
func (*BaseChannel) ClearGroup ¶
func (channel *BaseChannel) ClearGroup()
func (*BaseChannel) ClearUser ¶
func (channel *BaseChannel) ClearUser()
func (*BaseChannel) Close ¶ added in v3.0.59
func (channel *BaseChannel) Close(reason string) error
func (*BaseChannel) Dispose ¶ added in v3.0.59
func (channel *BaseChannel) Dispose()
func (*BaseChannel) Equals ¶
func (channel *BaseChannel) Equals(c Channel) bool
Equals 根据 id 判断是否相等.
func (*BaseChannel) GetBsid ¶
func (channel *BaseChannel) GetBsid() (bsid string)
func (*BaseChannel) GetClientIP ¶
func (channel *BaseChannel) GetClientIP() string
func (*BaseChannel) GetCloseCh ¶
func (channel *BaseChannel) GetCloseCh() chan string
GetCloseCh
PS: 只有 调用SetClosed() && 返回值为true 的情况下,才能向通道中写数据.
func (*BaseChannel) GetData ¶
func (channel *BaseChannel) GetData() (data interface{})
func (*BaseChannel) GetGroup ¶
func (channel *BaseChannel) GetGroup() (group string)
func (*BaseChannel) GetId ¶
func (channel *BaseChannel) GetId() (id string)
func (*BaseChannel) GetType ¶
func (channel *BaseChannel) GetType() string
func (*BaseChannel) GetUser ¶
func (channel *BaseChannel) GetUser() (user string)
func (*BaseChannel) Initialize ¶ added in v3.0.59
func (channel *BaseChannel) Initialize() error
func (*BaseChannel) Push ¶ added in v3.0.59
func (channel *BaseChannel) Push(data []byte) error
func (*BaseChannel) SetBsid ¶
func (channel *BaseChannel) SetBsid(bsid string)
func (*BaseChannel) SetClosed ¶
func (channel *BaseChannel) SetClosed() (flag bool)
SetClosed (写锁)
PS: 返回值如果为true,应当调用 Listeners.OnClose().
@return true: 设置成功
false: 设置失败(因为已经被设置关闭)
func (*BaseChannel) SetData ¶
func (channel *BaseChannel) SetData(data interface{})
func (*BaseChannel) SetGroup ¶
func (channel *BaseChannel) SetGroup(group string)
func (*BaseChannel) SetUser ¶
func (channel *BaseChannel) SetUser(user string)
type Channel ¶
type Channel interface { // Close 后端主动关闭通道. /* @param reason 关闭的原因 */ Close(reason string) error IsClosed() (rst bool) // SetClosed /* PS: 返回值如果为true,应当 向closeCh发送数据 || 调用Listeners.OnClose(). */ SetClosed() (flag bool) // GetCloseCh 获取关闭通道. /* PS: 只有 调用SetClosed() && 返回值为true 的情况下,才能向通道中写数据. */ GetCloseCh() chan string // Initialize 初始化Channel. Initialize() error // Dispose 释放Channel所持有的资源. Dispose() Push(data []byte) error GetClientIP() string GetType() string GetId() string GetBsid() string SetBsid(string) ClearBsid() GetUser() string SetUser(string) ClearUser() GetGroup() string SetGroup(string) ClearGroup() GetData() interface{} SetData(interface{}) ClearData() BindGroup(group string) BindUser(user string) BindBsid(bsid string) Equals(c Channel) bool }
type Listener ¶
type Listener interface { OnFailure(w http.ResponseWriter, r *http.Request, failureInfo string) OnHandshake(w http.ResponseWriter, r *http.Request, channel Channel) // OnMessage 收到 客户端 发来的消息. /* PS: 仅适用于WebSocket连接,因为SSE连接是单工的. */ OnMessage(channel Channel, messageType int, data []byte) // BeforeClosedByBackend 由于后端主动关闭连接,而触发的关闭事件. BeforeClosedByBackend(channel Channel, closeInfo string) OnClose(channel Channel, closeInfo string, bsid, user, group string) }
type Listeners ¶
type Listeners []Listener