Documentation
¶
Index ¶
- Variables
- func ServerWithAuthTimeout(authTimeout time.Duration) option.Opt[Server]
- func ServerWithConnLimiter(connLimiter *limiter.ConnLimiter) option.Opt[Server]
- func ServerWithDrainTimeout(drainTimeout time.Duration) option.Opt[Server]
- func ServerWithIdleScan(scanInterval, idleTimeout time.Duration) option.Opt[Server]
- type Config
- type Server
- type Upgrader
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidDeviceType = errors.New("invalid device type")
Functions ¶
func ServerWithAuthTimeout ¶
ServerWithAuthTimeout 设置连接建立后等待首帧 AUTH 的超时时间。
func ServerWithConnLimiter ¶
func ServerWithConnLimiter(connLimiter *limiter.ConnLimiter) option.Opt[Server]
ServerWithConnLimiter 设置连接准入限流器。
func ServerWithDrainTimeout ¶
ServerWithDrainTimeout 设置优雅关闭时等待存量连接排空的超时时间。
Types ¶
type Config ¶
type Config struct {
Host string // IP 地址,默认 0.0.0.0
Port int // 端口号,默认 10071
Network string // 网络协议,默认 tcp4
EnableLocalMode bool // 是自动获取 IP 地
}
Config 为 WebSocket 的相关配置。
func DefaultConfig ¶
func DefaultConfig() *Config
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) GracefulShutdown ¶
GracefulShutdown 优雅关闭 WebSocket 服务器。
顺序: 停止接受新连接 -> 停止 Kafka 消费 -> 等待存量连接排空 ( 带超时 ) -> 强制关闭剩余连接 -> 取消服务器 context。 注意不能先等待 ctx.Done 再取消 ctx——那会永久阻塞 ( 自锁 )。
type Upgrader ¶
type Upgrader struct {
// contains filtered or unexported fields
}
Upgrader 将 HTTP 连接升级为 WebSocket 连接。
注意:鉴权不在升级阶段完成——新协议要求连接建立后的第一帧必须为 AUTH, 携带后端签发的 JWT ( 契约见 api/proto/auth/v1/auth.proto )。 升级阶段只协商压缩扩展并解析设备类型等非敏感参数。
func NewUpgrader ¶
func NewUpgrader(compressionConfig compression.Config) *Upgrader
Click to show internal directories.
Click to hide internal directories.