biz

package
v0.0.0-...-cefb499 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const CheckNull = "CheckNull"
View Source
const RandomNum = 5

Variables

This section is empty.

Functions

func RandStringBytesMaskImperSrc

func RandStringBytesMaskImperSrc(n int) string

RandStringBytesMaskImperSrc 生成随机字符串

Types

type AdminCase

type AdminCase struct {
	IAdmin
}

func NewAdmin

func NewAdmin(admin IAdmin) *AdminCase

NewAdmin 实例化对象

type CheckFunc

type CheckFunc func(interface{}) (string, bool)

type IAdmin

type IAdmin interface {
	SendMsg(funcName string) func(c *gin.Context)
	HandlerWS(string, *websocket.AcceptOptions) func(c *gin.Context)
}

IAdmin 接口

type IClient

type IClient interface {
	// SendMes 发送消息 非阻塞 失败返回
	SendMes(msg IMessage) bool

	// MsgChan 返回一个可收取的channel 用于接收消息
	MsgChan() <-chan IMessage

	// GetCtx 返回context.Context
	GetCtx() context.Context

	// SetCtx 设置context
	SetCtx(context.Context)
	// Shutdown 回收资源
	// 多次调用无副作用!
	Shutdown()
}

IClient 客户端接口

type IHandle

type IHandle interface {
	Register(int32, TypeHandlerFunc) bool
	GetHandler(int32) (TypeHandlerFunc, bool)
}

IHandle 注册对应type处理函数

type IManage

type IManage interface {
	// Register 注册接口
	Register(key string) IClient

	// UnRegister 注销接口
	UnRegister(key string)

	// FindClient 查找在线客户端
	FindClient(key string) (IClient, bool)

	// FindClients 批量查找在线客户端
	FindClients(key ...string) []IClient

	// GetAll 查找所有客户端
	GetAll() []IClient
}

IManage 只提供用户管理存储

type IMessage

type IMessage interface {
	Marshal() ([]byte, error)
	Unmarshal(data []byte) error
	GetType() int32
	GetTo() string
}

IMessage 定义消息接口

type ITopic

type ITopic interface {
	// CreateTopic 创建topic
	CreateTopic(string)
	// DeleteTopic 删除topic
	DeleteTopic(string)

	// Subscribe 订阅
	Subscribe(topic, key string) bool

	// UnSubscribe 退订
	UnSubscribe(topic, key string) bool

	// GetTopicList 获取订阅topic的用户
	GetTopicList(topic string) []string
}

ITopic 订阅表

type TypeHandlerFunc

type TypeHandlerFunc func(IMessage) bool

TypeHandlerFunc 根据type处理handler

Jump to

Keyboard shortcuts

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