Documentation
¶
Index ¶
- Constants
- Variables
- func HmacSHA256(key string, data string) string
- func Md5(str string) (md5str string)
- func RandStringBytes(n int) string
- type DispatcherHandle
- type DispatcherHandleMap
- type MapStorage
- type StartResp
- type Storage
- type WsClient
- func (wsClient *WsClient) AuthSuccess()
- func (wsClient *WsClient) Close() error
- func (wsClient *WsClient) CloseWithType(t int) (err error)
- func (wsClient *WsClient) Dial(links ...string) error
- func (wsClient *WsClient) IsAuthed() bool
- func (wsClient *WsClient) Logger() *slog.Logger
- func (wsClient *WsClient) Reconnection(startResp StartResp) error
- func (wsClient *WsClient) Reset()
- func (wsClient *WsClient) Run()
- func (wsClient *WsClient) SendAuth() error
- func (wsClient *WsClient) SendHeartbeat() error
- func (wsClient *WsClient) SendMessage(msg proto.Message) error
- func (wsClient *WsClient) WithOnClose(onClose WsClientCloseCallback) *WsClient
- type WsClientCloseCallback
Constants ¶
View Source
const ( // CloseAuthFailed 鉴权失败 CloseAuthFailed = 1 // CloseActively 调用者主动关闭 CloseActively = 2 // CloseReadingConnError 读取链接错误 CloseReadingConnError = 3 // CloseReceivedShutdownMessage 收到关闭消息 CloseReceivedShutdownMessage = 4 // CloseTypeUnknown 未知原因 CloseTypeUnknown = 5 )
Variables ¶
View Source
var DefaultLoggerGenerator = func() *slog.Logger { return slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) }
DefaultLoggerGenerator 默认日志生成器 如果不设置,会使用 slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
Functions ¶
func HmacSHA256 ¶
func RandStringBytes ¶
Types ¶
type DispatcherHandleMap ¶
type DispatcherHandleMap map[uint32]DispatcherHandle
func (DispatcherHandleMap) Set ¶
func (dhm DispatcherHandleMap) Set(op uint32, handle DispatcherHandle) DispatcherHandleMap
type MapStorage ¶
type MapStorage struct {
// contains filtered or unexported fields
}
func NewMapStorage ¶
func NewMapStorage() *MapStorage
func (*MapStorage) Del ¶
func (s *MapStorage) Del(key string) error
type WsClient ¶
type WsClient struct {
// contains filtered or unexported fields
}
func NewWsClient ¶
func NewWsClient(startResp StartResp, dispatcherHandleMap DispatcherHandleMap, logger *slog.Logger) *WsClient
func StartWebsocket ¶
func StartWebsocket( startResp StartResp, dispatcherHandleMap DispatcherHandleMap, onCloseFunc WsClientCloseCallback, logger *slog.Logger, ) (*WsClient, error)
StartWebsocket 启动websocket 此方法会一键完成鉴权,心跳,消息分发注册
func (*WsClient) AuthSuccess ¶
func (wsClient *WsClient) AuthSuccess()
func (*WsClient) CloseWithType ¶
func (*WsClient) Reconnection ¶
func (*WsClient) SendMessage ¶
SendMessage 发送消息
func (*WsClient) WithOnClose ¶
func (wsClient *WsClient) WithOnClose(onClose WsClientCloseCallback) *WsClient
Click to show internal directories.
Click to hide internal directories.