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.
|
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
|
|
|
|
WSServerConf 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"`
|
|
|
|
|
// check origin
|
|
|
|
|
CheckOrigin func(*http.Request) bool
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (c WSServerConf) IsTLS() bool {
|
|
|
|
|
return len(c.TLSCertificate) > 0 && len(c.TLSKey) > 0
|
|
|
|
|
}
|