Documentation ¶
Index ¶
- Constants
- func EventListener(interval time.Duration, eventFunc func(), stopChan <-chan struct{})
- func NewClientManager()
- 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
- func (m *ClientManager) Close(client *Client)
- func (m *ClientManager) GetAllClient() (clients []*Client)
- func (m *ClientManager) GetClient(fd string) (client *Client, err error)
- func (m *ClientManager) RegisterClient(client *Client)
- func (m *ClientManager) Scheduler()
- func (m *ClientManager) UnsetClient(fd string) (err error)
- type DisposeFunc
- type DistributeHandler
- type JsonHandler
- type Message
- type MiddlewareFunc
- type ProtoHandler
- type Request
- type Response
- type Route
- type Router
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 // 每个连接唯一标识 Request *http.Request // 请求 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
func (*ClientManager) UnsetClient ¶ added in v1.1.3
func (m *ClientManager) UnsetClient(fd string) (err error)
UnsetClient Unset client
type DisposeFunc ¶
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 MiddlewareFunc ¶
type MiddlewareFunc func(DisposeFunc) DisposeFunc
type ProtoHandler ¶
type ProtoHandler struct{}
func NewProtoHandler ¶
func NewProtoHandler() *ProtoHandler
func (*ProtoHandler) Distribute ¶
func (p *ProtoHandler) Distribute(client *Client, message []byte) (err error)
type Response ¶
type Response struct { Code uint32 `json:"code"` Message string `json:"message"` Content string `json:"content"` }
func NewResponse ¶
func NewResponse() *Response
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func (*Route) Use ¶
func (r *Route) Use(middleware MiddlewareFunc)
Use Route Create a new middleware chain
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
var (
RouteManager *Router
)
func (*Router) Register ¶
func (r *Router) Register(event string, handler DisposeFunc, middlewareFunc ...MiddlewareFunc)
Register event to memory
Source Files ¶
Click to show internal directories.
Click to hide internal directories.