websocket

package
v0.0.0-...-4f29f3d Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeWs

func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request)

ServeWs handles websocket requests from the peer.

Types

type Broadcast

type Broadcast struct {
	// contains filtered or unexported fields
}

Broadcast maintains the set of active clients and broadcasts messages to the clients.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the hub.

type DispatchFunc

type DispatchFunc func(uid int64, msg []byte)

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func GetHub

func GetHub() *Hub

func NewHub

func NewHub(options ...Option) *Hub

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) Send2User

func (h *Hub) Send2User(id, ts int64, b []byte)

type Logger

type Logger interface {
	Info(logs ...interface{})
	Warn(logs ...interface{})
	Debug(logs ...interface{})
	Error(logs ...interface{})
}

type LoginFunc

type LoginFunc func(w http.ResponseWriter, r *http.Request) (int64, error)

type Option

type Option func(d *Hub)

func WithConcurrent

func WithConcurrent(n int) Option

func WithLogger

func WithLogger(f Logger) Option

func WithLogin

func WithLogin(f LoginFunc) Option

func WithReceive

func WithReceive(f DispatchFunc) Option

func WithRedis

func WithRedis(maxCount, maxTtl int, redis Redis) Option

WithRedis maxCount 单个用户保存的最大消息数, maxTtl 缓存消息最长时间,单位秒

type Redis

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
}

type RedisClient

type RedisClient struct {
	MaxCount int
	MaxTtl   int
	// contains filtered or unexported fields
}

func NewRedisCache

func NewRedisCache(maxCount, maxTtl int, redis Redis) *RedisClient

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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