package server import ( "net" cwf "git.loafle.net/commons_go/websocket_fasthttp" "github.com/valyala/fasthttp" ) func newServerHandler() cwf.ServerHandler { sh := &ServerHandlers{} return sh } type ServerHandlers struct { cwf.ServerHandlers } func (sh *ServerHandlers) Listen() (net.Listener, error) { return net.Listen("tcp4", ":19090") } func (sh *ServerHandlers) CheckOrigin(ctx *fasthttp.RequestCtx) bool { if origin := string(ctx.Request.Header.Peek("Origin")); origin != "" { ctx.Response.Header.Set("Access-Control-Allow-Origin", origin) if string(ctx.Method()) == "OPTIONS" && string(ctx.Request.Header.Peek("Access-Control-Request-Method")) != "" { ctx.Response.Header.Set("Access-Control-Allow-Headers", "Content-Type, Accept") ctx.Response.Header.Set("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, DELETE") } } return true } func (sh *ServerHandlers) OnError(ctx *fasthttp.RequestCtx, status int, reason error) { // no op } func (sh *ServerHandlers) OnStart() { // no op } func (sh *ServerHandlers) OnStop() { // no op }