Documentation
¶
Index ¶
- func BytesToString(b []byte) string
- func Metrics(w http.ResponseWriter)
- func SendMessage(clientId string, msgType message.Type, msg string) error
- func Serve(writer http.ResponseWriter, request *http.Request)
- func StringToBytes(s string) []byte
- type Authenticator
- type BinaryMessageHandler
- type Client
- type Handler
- type Hub
- type JWTAuthenticator
- type TextMessageHandler
- type UnimplementedBinaryMessageHandler
- type UnimplementedTextMessageHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SendMessage ¶
SendMessage 服务端向客户端发送消息
Types ¶
type Authenticator ¶
type BinaryMessageHandler ¶
type BinaryMessageHandler interface {
Handler(ctx context.Context, clientId, userId string, data []byte) error
// contains filtered or unexported methods
}
BinaryMessageHandler 二进制消息处理器
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) IsClientConnected ¶
IsClientConnected 添加客户端连接状态检查方法
func (*Hub) SetBinaryMessageHandler ¶
func (h *Hub) SetBinaryMessageHandler(handler BinaryMessageHandler)
func (*Hub) SetTextMessageHandler ¶
func (h *Hub) SetTextMessageHandler(handler TextMessageHandler)
type JWTAuthenticator ¶
type JWTAuthenticator struct{}
func (*JWTAuthenticator) Authenticate ¶
func (jwt *JWTAuthenticator) Authenticate(r *http.Request) (map[string]interface{}, error)
type TextMessageHandler ¶
type TextMessageHandler interface {
Handler(ctx context.Context, clientId, userId string, data []byte) error
// contains filtered or unexported methods
}
TextMessageHandler 文本消息处理器
type UnimplementedBinaryMessageHandler ¶
type UnimplementedBinaryMessageHandler struct{}
type UnimplementedTextMessageHandler ¶
type UnimplementedTextMessageHandler struct{}
Click to show internal directories.
Click to hide internal directories.