Documentation
¶
Index ¶
- func BytesToString(b []byte) string
- func Metrics(w http.ResponseWriter)
- func SendMessage(clientId string, msgType message.Type, msg string) error
- func StringToBytes(s string) []byte
- func WebsocketServe(writer http.ResponseWriter, request *http.Request)
- type Authenticator
- type Client
- type Handler
- type Hub
- type JWTAuthenticator
- type MessageHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WebsocketServe ¶
func WebsocketServe(writer http.ResponseWriter, request *http.Request)
WebsocketServe 处理 WebSocket 连接请求
Types ¶
type Authenticator ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 是一个中间人,负责 WebSocket 连接和 Hub 之间的通信
type Hub ¶
type Hub struct {
// 互斥锁,保护 userClients 以及 clients 的读写
sync.RWMutex
// contains filtered or unexported fields
}
Hub 维护了所有的客户端连接
var HubBus *Hub
func (*Hub) SetMessageHandler ¶
func (h *Hub) SetMessageHandler(handler MessageHandler)
type JWTAuthenticator ¶
type JWTAuthenticator struct{}
func (*JWTAuthenticator) Authenticate ¶
func (J *JWTAuthenticator) Authenticate(r *http.Request) (map[string]interface{}, error)
Click to show internal directories.
Click to hide internal directories.