1 Star 0 Fork 0

zhonglin.liu / dao_socket

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
option.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
zhonglin.liu 提交于 2022-05-31 00:46 . package
package websocket
import (
"github.com/go-redis/redis"
"net/http"
"time"
)
type Option func(d *Hub)
type LoginFunc func(w http.ResponseWriter, r *http.Request) (int64, error)
type DispatchFunc func(uid int64, msg []byte)
type Logger interface {
Info(logs ...interface{})
Warn(logs ...interface{})
Debug(logs ...interface{})
Error(logs ...interface{})
}
type Redis interface {
ZAdd(key string, members ...redis.Z) *redis.IntCmd
Get(key string) *redis.StringCmd
Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
ZRange(key string, start, stop int64) *redis.StringSliceCmd
ZRem(key string, members ...interface{}) *redis.IntCmd
ZCard(key string) *redis.IntCmd
ZRemRangeByRank(key string, start, stop int64) *redis.IntCmd
MGet(keys ...string) *redis.SliceCmd
Pipeline() redis.Pipeliner
}
func WithLogin(f LoginFunc) Option {
return func(d *Hub) {
d.login = f
}
}
func WithLogger(f Logger) Option {
return func(d *Hub) {
d.logger = f
}
}
func WithReceive(f DispatchFunc) Option {
return func(d *Hub) {
d.dispatch = f
}
}
func WithConcurrent(n int) Option {
return func(d *Hub) {
d.concurrent = make(chan struct{}, n)
}
}
// WithRedis maxCount 单个用户保存的最大消息数, maxTtl 缓存消息最长时间,单位秒
func WithRedis(maxCount, maxTtl int, redis Redis) Option {
return func(d *Hub) {
d.redis = NewRedisCache(maxCount, maxTtl, redis)
}
}
Go
1
https://gitee.com/zhonglin-liu/dao_socket.git
git@gitee.com:zhonglin-liu/dao_socket.git
zhonglin-liu
dao_socket
dao_socket
4f29f3d82524

搜索帮助

53164aa7 5694891 3bd8fe86 5694891