Documentation
¶
Index ¶
- Variables
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CodecName() string
- func (c *Conn) Context() context.Context
- func (c *Conn) GetMeta(key string) (any, bool)
- func (c *Conn) ID() string
- func (c *Conn) LastActiveTime() time.Time
- func (c *Conn) SendResp(resp *types.Response) error
- func (c *Conn) SetMeta(key string, val any)
- func (c *Conn) Subscribe(topics ...string)
- func (c *Conn) Subscriptions() []string
- func (c *Conn) Unsubscribe(topics ...string)
- type ConnManager
- type Handler
- type Middleware
- type Server
- func (s *Server) Broadcast(resp *types.Response)
- func (s *Server) BroadcastFilter(resp *types.Response, filter func(*Conn) bool)
- func (s *Server) Codec() codec.Codec
- func (s *Server) ConnManager() *ConnManager
- func (s *Server) Handle(action string, handler Handler)
- func (s *Server) OnConnect(fn func(*Conn, *http.Request))
- func (s *Server) OnDisconnect(fn func(*Conn))
- func (s *Server) Publish(topic string, resp *types.Response)
- func (s *Server) PublishFilter(topic string, resp *types.Response, filter func(*Conn) bool)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Shutdown()
- func (s *Server) TopicCount(topic string) int
- func (s *Server) Topics() []string
- func (s *Server) Use(middleware ...Middleware)
- type ServerOption
- func WithServerAllowedOrigins(fn func(origin string) bool) ServerOption
- func WithServerCodec(name string) ServerOption
- func WithServerHeartbeat(d time.Duration) ServerOption
- func WithServerMaxConns(n int) ServerOption
- func WithServerMaxMessageSize(size int) ServerOption
- func WithServerSendBufferSize(n int) ServerOption
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrSendFull = errors.New("send channel full")
ErrSendFull 发送通道满(背压)
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn WebSocket 连接(服务端侧)
func (*Conn) Subscriptions ¶
Subscriptions 获取当前连接已订阅的所有 topic
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
func (*ConnManager) Range ¶
func (cm *ConnManager) Range(fn func(*Conn) bool)
Range 遍历所有连接,fn 返回 false 停止
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server WebSocket 服务端 实现 http.Handler 接口,可接入用户自建的 HTTP 服务器
func (*Server) BroadcastFilter ¶
BroadcastFilter 向满足条件的连接广播消息
func (*Server) PublishFilter ¶
PublishFilter 向某 topic 中满足条件的订阅者发布消息
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP 实现 http.Handler 接口
func (*Server) TopicCount ¶
TopicCount 获取某 topic 的订阅者数量
type ServerOption ¶
type ServerOption func(*serverConfig)
ServerOption 服务端配置选项
func WithServerAllowedOrigins ¶
func WithServerAllowedOrigins(fn func(origin string) bool) ServerOption
WithServerAllowedOrigins 设置允许的跨域来源验证函数
func WithServerCodec ¶
func WithServerCodec(name string) ServerOption
WithServerCodec 设置编解码器,支持 "json"/"msgpack"/"protobuf",默认 "json"
func WithServerHeartbeat ¶
func WithServerHeartbeat(d time.Duration) ServerOption
WithServerHeartbeat 设置空闲超时检测间隔,0 禁用
func WithServerMaxMessageSize ¶
func WithServerMaxMessageSize(size int) ServerOption
WithServerMaxMessageSize 设置最大消息大小(字节),0 不限制
func WithServerSendBufferSize ¶
func WithServerSendBufferSize(n int) ServerOption
WithServerSendBufferSize 设置每连接发送缓冲区大小
Click to show internal directories.
Click to hide internal directories.