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 }