ws

package module
v2.0.0-...-f9caf38 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 17 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(opts ...ClientOption) network.Client

Types

type CheckOriginFunc

type CheckOriginFunc func(r *http.Request) bool

type ClientOption

type ClientOption func(o *clientOptions)

func WithClientDialTimeout

func WithClientDialTimeout(dialTimeout time.Duration) ClientOption

WithClientDialTimeout 设置拨号超时时间

func WithClientHeartbeatInterval

func WithClientHeartbeatInterval(heartbeatInterval time.Duration) ClientOption

WithClientHeartbeatInterval 设置心跳间隔时间

func WithClientUrl

func WithClientUrl(url string) ClientOption

WithClientUrl 设置拨号链接

func WithClientWriteQueueSize

func WithClientWriteQueueSize(writeQueueSize int) ClientOption

WithClientWriteQueueSize 设置写队列大小

func WithClientWriteTimeout

func WithClientWriteTimeout(writeTimeout time.Duration) ClientOption

WithClientWriteTimeout 设置写超时时间

type HeartbeatMechanism

type HeartbeatMechanism string
const (
	RespHeartbeat HeartbeatMechanism = "resp" // 响应式心跳
	TickHeartbeat HeartbeatMechanism = "tick" // 主动定时心跳
)

type Server

type Server interface {
	network.Server
	// OnUpgrade 监听HTTP请求升级
	OnUpgrade(handler UpgradeHandler)
}

func NewServer

func NewServer(opts ...ServerOption) Server

type ServerOption

type ServerOption func(o *serverOptions)

func WithServerAddr

func WithServerAddr(addr string) ServerOption

WithServerAddr 设置监听地址

func WithServerAuthorizeTimeout

func WithServerAuthorizeTimeout(authorizeTimeout time.Duration) ServerOption

WithServerAuthorizeTimeout 设置授权超时时间

func WithServerCheckOrigin

func WithServerCheckOrigin(checkOrigin CheckOriginFunc) ServerOption

WithServerCheckOrigin 设置Websocket跨域检测函数

func WithServerCredentials

func WithServerCredentials(certFile, keyFile string) ServerOption

WithServerCredentials 设置服务器证书和秘钥

func WithServerHeartbeatInterval

func WithServerHeartbeatInterval(heartbeatInterval time.Duration) ServerOption

WithServerHeartbeatInterval 设置心跳检测间隔时间

func WithServerHeartbeatMechanism

func WithServerHeartbeatMechanism(heartbeatMechanism HeartbeatMechanism) ServerOption

WithServerHeartbeatMechanism 设置心跳机制

func WithServerMaxConnNum

func WithServerMaxConnNum(maxConnNum int) ServerOption

WithServerMaxConnNum 设置连接的最大连接数

func WithServerPath

func WithServerPath(path string) ServerOption

WithServerPath 设置Websocket的连接路径

func WithServerWriteQueueSize

func WithServerWriteQueueSize(writeQueueSize int) ServerOption

WithServerWriteQueueSize 设置写入队列大小

func WithServerWriteTimeout

func WithServerWriteTimeout(writeTimeout time.Duration) ServerOption

WithServerWriteTimeout 设置写超时时间

type UpgradeHandler

type UpgradeHandler func(w http.ResponseWriter, r *http.Request) (allowed bool)

Jump to

Keyboard shortcuts

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