Documentation
¶
Index ¶
- Constants
- func EventListener(interval time.Duration, eventFunc func(), stopChan <-chan struct{})
- func NewClientManager()
- func Register(event string, handler DisposeFunc)
- func Upgrade(w http.ResponseWriter, req *http.Request)
- type Client
- func (c *Client) Close()
- func (c *Client) CloseSubscribe(channel string) (err error)
- func (c *Client) CreatChan() (channel string, err error)
- func (c *Client) GetAllChan() (channels []string, pubSubs []*redis.PubSub)
- func (c *Client) GetChan(channel string) (pubSub *redis.PubSub, err error)
- func (c *Client) Heartbeat()
- func (c *Client) IsHeartbeatTimeout(currentTime int64) (timeout bool)
- func (c *Client) Publish(channel string, message []byte) (err error)
- func (c *Client) Read()
- func (c *Client) Receive()
- func (c *Client) SendMessage(message []byte)
- func (c *Client) SetHeartbeatTime(currentTime int64)
- func (c *Client) Subscribe(channel string) (err error)
- func (c *Client) Unsubscribe(channel string) (err error)
- func (c *Client) Write()
- type ClientManager
- type DisposeFunc
- type DistributeHandler
- type JsonHandler
- type Message
- type Middleware
- type ProtoHandler
- type Request
- type Response
Constants ¶
View Source
const (
Max = 1000
)
Variables ¶
This section is empty.
Functions ¶
func EventListener ¶
func NewClientManager ¶
func NewClientManager()
Types ¶
type Client ¶
type Client struct {
Fd string // 每个连接唯一标识
Addr string // 客户端ip地址
Socket *websocket.Conn // 用户连接
Send chan []byte // 待发送的数据
Channel sync.Map // 订阅频道
OwnerChannel sync.Map // 自己创建的频道
FirstTime int64 // 首次连接事件
HeartbeatTime int64 // 用户上次心跳时间
Timeout int64 // 超时断连时间
Protocol int // 协议类型
// contains filtered or unexported fields
}
func (*Client) CloseSubscribe ¶
func (*Client) GetAllChan ¶
GetAllChan Get all channels
func (*Client) Heartbeat ¶
func (c *Client) Heartbeat()
Heartbeat The scheduled task clears timeout links
func (*Client) IsHeartbeatTimeout ¶
func (*Client) SendMessage ¶
SendMessage Message distribution
func (*Client) SetHeartbeatTime ¶
func (*Client) Unsubscribe ¶
Unsubscribe unsubscribe
type ClientManager ¶
type ClientManager struct {
Pool sync.Map
Register chan *Client
Unset chan *Client
Total uint
Max uint
Broadcast chan []byte
Errs chan error
}
ClientManager Client pool manager
var (
Manager *ClientManager
)
func (*ClientManager) GetAllClient ¶
func (m *ClientManager) GetAllClient() (clients []*Client)
GetAllClient Get all client
func (*ClientManager) GetClient ¶
func (m *ClientManager) GetClient(fd string) (client *Client, err error)
GetClient Obtain the client according to fd
func (*ClientManager) RegisterClient ¶
func (m *ClientManager) RegisterClient(client *Client)
RegisterClient Register client
func (*ClientManager) Scheduler ¶
func (m *ClientManager) Scheduler()
Scheduler Start the websocket scheduler
type DisposeFunc ¶
func GetHandler ¶
func GetHandler(event string) (handler DisposeFunc, err error)
GetHandler Get register's func
type DistributeHandler ¶
type JsonHandler ¶
type JsonHandler struct{}
func NewJsonHandler ¶
func NewJsonHandler() *JsonHandler
func (*JsonHandler) Distribute ¶
func (j *JsonHandler) Distribute(client *Client, message []byte) (err error)
type Middleware ¶
type Middleware func(next http.HandlerFunc) http.HandlerFunc
type ProtoHandler ¶
type ProtoHandler struct{}
func NewProtoHandler ¶
func NewProtoHandler() *ProtoHandler
func (*ProtoHandler) Distribute ¶
func (p *ProtoHandler) Distribute(client *Client, message []byte) (err error)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.