Documentation
¶
Index ¶
- func NewClient(opts ...ClientOption) network.Client
- type CheckOriginFunc
- type ClientOption
- func WithClientCloseTimeout(closeTimeout time.Duration) ClientOption
- func WithClientCompression(enableCompression bool) ClientOption
- func WithClientCompressionLevel(compressionLevel int) ClientOption
- func WithClientCredentials(caFile string, serverName string) ClientOption
- func WithClientDialTimeout(dialTimeout time.Duration) ClientOption
- func WithClientHeartbeatInterval(heartbeatInterval time.Duration) ClientOption
- func WithClientReadBufferSize(readBufferSize int) ClientOption
- func WithClientTLSConfig(tlsConfig *tls.Config) ClientOption
- func WithClientUrl(url string) ClientOption
- func WithClientWriteQueueSize(writeQueueSize int) ClientOption
- func WithClientWriteTimeout(writeTimeout time.Duration) ClientOption
- type HeartbeatMechanism
- type ProxyMode
- type ProxyOptions
- type Server
- type ServerOption
- func WithServerAddr(addr string) ServerOption
- func WithServerAuthorizeTimeout(authorizeTimeout time.Duration) ServerOption
- func WithServerCheckOrigin(checkOrigin CheckOriginFunc) ServerOption
- func WithServerCloseTimeout(closeTimeout time.Duration) ServerOption
- func WithServerCompressionLevel(compressionLevel int) ServerOption
- func WithServerCredentials(certFile, keyFile string) ServerOption
- func WithServerEnableCompression(enableCompression bool) ServerOption
- func WithServerHeartbeatInterval(heartbeatInterval time.Duration) ServerOption
- func WithServerHeartbeatMechanism(heartbeatMechanism HeartbeatMechanism) ServerOption
- func WithServerMaxConnNum(maxConnNum int) ServerOption
- func WithServerPath(path string) ServerOption
- func WithServerProxyMode(proxyMode ProxyMode) ServerOption
- func WithServerProxyOptions(proxyOpts ProxyOptions) ServerOption
- func WithServerReadBufferSize(readBufferSize int) ServerOption
- func WithServerWriteBufferSize(writeBufferSize int) ServerOption
- func WithServerWriteQueueSize(writeQueueSize int) ServerOption
- func WithServerWriteTimeout(writeTimeout time.Duration) ServerOption
- type TrustProxyOptions
- type UpgradeHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
func NewClient(opts ...ClientOption) network.Client
NewClient returns a new client.
Types ¶
type CheckOriginFunc ¶
type ClientOption ¶
type ClientOption func(o *clientOptions)
func WithClientCloseTimeout ¶
func WithClientCloseTimeout(closeTimeout time.Duration) ClientOption
WithClientCloseTimeout sets the graceful close timeout.
When the write queue has not drained before the timeout elapses, the wait is abandoned and the connection is closed forcibly. The default value of 0 means no limit.
func WithClientCompression ¶
func WithClientCompression(enableCompression bool) ClientOption
WithClientCompression sets whether to enable compression.
func WithClientCompressionLevel ¶
func WithClientCompressionLevel(compressionLevel int) ClientOption
WithClientCompressionLevel sets the compression level.
func WithClientCredentials ¶
func WithClientCredentials(caFile string, serverName string) ClientOption
WithClientCredentials sets the CA certificate and the server name to verify.
func WithClientDialTimeout ¶
func WithClientDialTimeout(dialTimeout time.Duration) ClientOption
WithClientDialTimeout sets the dial timeout.
func WithClientHeartbeatInterval ¶
func WithClientHeartbeatInterval(heartbeatInterval time.Duration) ClientOption
WithClientHeartbeatInterval sets the heartbeat interval.
func WithClientReadBufferSize ¶
func WithClientReadBufferSize(readBufferSize int) ClientOption
WithClientReadBufferSize sets the read buffer size.
func WithClientTLSConfig ¶
func WithClientTLSConfig(tlsConfig *tls.Config) ClientOption
WithClientTLSConfig sets the TLS config.
func WithClientWriteQueueSize ¶
func WithClientWriteQueueSize(writeQueueSize int) ClientOption
WithClientWriteQueueSize sets the write queue size.
func WithClientWriteTimeout ¶
func WithClientWriteTimeout(writeTimeout time.Duration) ClientOption
WithClientWriteTimeout sets the write timeout.
type HeartbeatMechanism ¶
type HeartbeatMechanism string
const ( RespHeartbeat HeartbeatMechanism = "resp" // Responsive heartbeat TickHeartbeat HeartbeatMechanism = "tick" // Active tick heartbeat )
type ProxyOptions ¶
type ProxyOptions struct {
ProxyHeader string `json:"proxyHeader"` // Client IP header, defaults to "X-Forwarded-For"
PortHeader string `json:"portHeader"` // Client port header, defaults to "X-Forwarded-Port"
TrustProxy TrustProxyOptions `json:"trustProxy"` // Trust proxy config
}
type Server ¶
type Server interface {
network.Server
// OnUpgrade registers the handler invoked when an HTTP request is upgraded.
OnUpgrade(handler UpgradeHandler)
}
Server is the WebSocket server interface.
type ServerOption ¶
type ServerOption func(o *serverOptions)
func WithServerAddr ¶
func WithServerAddr(addr string) ServerOption
WithServerAddr sets the listen address.
func WithServerAuthorizeTimeout ¶
func WithServerAuthorizeTimeout(authorizeTimeout time.Duration) ServerOption
WithServerAuthorizeTimeout sets the authorization timeout.
func WithServerCheckOrigin ¶
func WithServerCheckOrigin(checkOrigin CheckOriginFunc) ServerOption
WithServerCheckOrigin sets the WebSocket origin check function.
func WithServerCloseTimeout ¶
func WithServerCloseTimeout(closeTimeout time.Duration) ServerOption
WithServerCloseTimeout sets the graceful close timeout.
When the write queue has not drained before the timeout elapses, the wait is abandoned and the connection is closed forcibly. The default value of 0 means no limit.
func WithServerCompressionLevel ¶
func WithServerCompressionLevel(compressionLevel int) ServerOption
WithServerCompressionLevel sets the compression level.
func WithServerCredentials ¶
func WithServerCredentials(certFile, keyFile string) ServerOption
WithServerCredentials sets the server certificate and key.
func WithServerEnableCompression ¶
func WithServerEnableCompression(enableCompression bool) ServerOption
WithServerEnableCompression sets whether to enable compression.
func WithServerHeartbeatInterval ¶
func WithServerHeartbeatInterval(heartbeatInterval time.Duration) ServerOption
WithServerHeartbeatInterval sets the heartbeat check interval.
func WithServerHeartbeatMechanism ¶
func WithServerHeartbeatMechanism(heartbeatMechanism HeartbeatMechanism) ServerOption
WithServerHeartbeatMechanism sets the heartbeat mechanism.
func WithServerMaxConnNum ¶
func WithServerMaxConnNum(maxConnNum int) ServerOption
WithServerMaxConnNum sets the maximum number of connections.
func WithServerPath ¶
func WithServerPath(path string) ServerOption
WithServerPath sets the WebSocket connection path.
func WithServerProxyMode ¶
func WithServerProxyMode(proxyMode ProxyMode) ServerOption
WithServerProxyMode sets the proxy mode.
func WithServerProxyOptions ¶
func WithServerProxyOptions(proxyOpts ProxyOptions) ServerOption
WithServerProxyOptions sets the proxy options.
func WithServerReadBufferSize ¶
func WithServerReadBufferSize(readBufferSize int) ServerOption
WithServerReadBufferSize sets the read buffer size.
func WithServerWriteBufferSize ¶
func WithServerWriteBufferSize(writeBufferSize int) ServerOption
WithServerWriteBufferSize sets the write buffer size.
func WithServerWriteQueueSize ¶
func WithServerWriteQueueSize(writeQueueSize int) ServerOption
WithServerWriteQueueSize sets the write queue size.
func WithServerWriteTimeout ¶
func WithServerWriteTimeout(writeTimeout time.Duration) ServerOption
WithServerWriteTimeout sets the write timeout.
type TrustProxyOptions ¶
type TrustProxyOptions struct {
Enable bool `json:"enable"` // Whether to trust proxies, defaults to false
Proxies []string `json:"proxies"` // List of trusted proxy IP addresses or CIDR ranges
LinkLocal bool `json:"linkLocal"` // Whether to trust all link-local IP ranges (e.g. 169.254.0.0/16, fe80::/10)
Loopback bool `json:"loopback"` // Whether to trust all loopback IP ranges (e.g. 127.0.0.0/8, ::1/128)
Private bool `json:"private"` // Whether to trust all private IP ranges (e.g. 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7)
// contains filtered or unexported fields
}
type UpgradeHandler ¶
type UpgradeHandler func(w http.ResponseWriter, r *http.Request) (allowed bool)
UpgradeHandler is the handler invoked when an HTTP request is upgraded to the WebSocket protocol.
It reports whether the upgrade is allowed.