You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nnet/config/server_ws.go

40 lines
1.1 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package config
import (
"net/http"
"time"
)
type (
WSConf struct {
// Addr 服务地址
// 地址可直接使用hostname,但强烈不建议这样做,可能会同时监听多个本地IP
// 如果端口号不填或端口号为0例如"127.0.0.1:" 或 ":0",服务端将选择随机可用端口
Addr string `json:",default=0.0.0.0:9876,env=WS_ADDR"`
// Path 监听路径 /WebsocketPath
Path string `json:",default=/,env=WS_PATH"`
// HandshakeTimeout 握手超时时间默认0
HandshakeTimeout time.Duration `json:",default=0"`
// ReadBufferSize 读缓冲区大小
ReadBufferSize int `json:",default=2048"`
// WriteBufferSize 写缓冲区大小
WriteBufferSize int `json:",default=2048"`
// Compression 是否使用压缩协议
Compression bool `json:",default=false"`
// TLSCertificate 证书地址
TLSCertificate string `json:",optional"`
// TLS 证书key地址
TLSKey string `json:",optional"`
}
WSServerFullConf struct {
WSConf
WSEvent `json:"-"`
// check origin
CheckOrigin func(*http.Request) bool `json:"-"`
}
)
func (c WSConf) IsTLS() bool {
return len(c.TLSCertificate) > 0 && len(c.TLSKey) > 0
}