basic

package
v0.0.0-...-d1d8880 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

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 HmacSHA256(key string, data string) string

func Md5

func Md5(str string) (md5str string)

func RandStringBytes

func RandStringBytes(n int) string

Types

type DispatcherHandle

type DispatcherHandle func(wsClient *WsClient, msg *proto.Message) error

type DispatcherHandleMap

type DispatcherHandleMap map[uint32]DispatcherHandle

func (DispatcherHandleMap) Set

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

func (*MapStorage) Get

func (s *MapStorage) Get(key string) ([]byte, error)

func (*MapStorage) Set

func (s *MapStorage) Set(key string, val []byte) error

type StartResp

type StartResp interface {
	GetAuthBody() []byte
	GetLinks() []string
}

type Storage

type Storage interface {
	Get(key string) ([]byte, error)
	Set(key string, val []byte) error
	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) Close

func (wsClient *WsClient) Close() error

func (*WsClient) CloseWithType

func (wsClient *WsClient) CloseWithType(t int) (err error)

func (*WsClient) Dial

func (wsClient *WsClient) Dial(links ...string) error

Dial 链接

func (*WsClient) IsAuthed

func (wsClient *WsClient) IsAuthed() bool

func (*WsClient) Logger

func (wsClient *WsClient) Logger() *slog.Logger

func (*WsClient) Reconnection

func (wsClient *WsClient) Reconnection(startResp StartResp) error

func (*WsClient) Reset

func (wsClient *WsClient) Reset()

func (*WsClient) Run

func (wsClient *WsClient) Run()

func (*WsClient) SendAuth

func (wsClient *WsClient) SendAuth() error

SendAuth 发送鉴权信息

func (*WsClient) SendHeartbeat

func (wsClient *WsClient) SendHeartbeat() error

SendHeartbeat 发送心跳

func (*WsClient) SendMessage

func (wsClient *WsClient) SendMessage(msg proto.Message) error

SendMessage 发送消息

func (*WsClient) WithOnClose

func (wsClient *WsClient) WithOnClose(onClose WsClientCloseCallback) *WsClient

type WsClientCloseCallback

type WsClientCloseCallback func(wsClient *WsClient, startResp StartResp, closeType int, AppClient ...*live.Client)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL