deprecated_overflow_gateway.../server_handlers.go
crusader 8299f95f4c ing
2017-08-31 19:08:14 +09:00

68 lines
1.7 KiB
Go

package overflow_gateway_websocket
import (
"time"
uuid "github.com/satori/go.uuid"
"github.com/valyala/fasthttp"
)
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
)
// 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
}
}