deprecated_overflow_gateway.../server_handlers.go

68 lines
1.7 KiB
Go
Raw Normal View History

2017-08-31 08:58:29 +00:00
package overflow_gateway_websocket
import (
"time"
uuid "github.com/satori/go.uuid"
"github.com/valyala/fasthttp"
)
2017-08-31 10:08:14 +00:00
const (
// DefaultHandshakeTimeout is default value of websocket handshake Timeout
DefaultHandshakeTimeout = 0
// DefaultReadBufferSize is default value of Read Buffer Size
DefaultReadBufferSize = 4096
// DefaultWriteBufferSize is default value of Write Buffer Size
DefaultWriteBufferSize = 4096
// DefaultEnableCompression is default value of support compression
DefaultEnableCompression = false
)
2017-08-31 08:58:29 +00:00
// ServerHandlers is implementation of the Server handler interface
type ServerHandlers struct {
HandshakeTimeout time.Duration
ReadBufferSize int
WriteBufferSize int
EnableCompression bool
}
func (sh *ServerHandlers) GetHandshakeTimeout() time.Duration {
return sh.HandshakeTimeout
}
func (sh *ServerHandlers) GetReadBufferSize() int {
return sh.ReadBufferSize
}
func (sh *ServerHandlers) GetWriteBufferSize() int {
return sh.WriteBufferSize
}
func (sh *ServerHandlers) GetEnableCompression() bool {
return sh.EnableCompression
}
func (sh *ServerHandlers) OnConnection(soc Socket) {
}
func (sh *ServerHandlers) OnDisconnected(soc Socket) {
}
func (sh *ServerHandlers) OnCheckOrigin(ctx *fasthttp.RequestCtx) bool {
return true
}
func (sh *ServerHandlers) OnError(ctx *fasthttp.RequestCtx, status int, reason error) {
}
func (sh *ServerHandlers) OnIDGenerate(ctx *fasthttp.RequestCtx) string {
return uuid.NewV4().String()
}
// Validate validates the configuration
func (sh *ServerHandlers) Validate() {
if sh.ReadBufferSize <= 0 {
sh.ReadBufferSize = DefaultReadBufferSize
}
if sh.WriteBufferSize <= 0 {
sh.WriteBufferSize = DefaultWriteBufferSize
}
}