package server import ( cwf "git.loafle.net/commons_go/websocket_fasthttp" oogws "git.loafle.net/overflow/overflow_gateway_websocket/server" "github.com/valyala/fasthttp" ) func NewServerHandler() ServerHandler { sh := &ServerHandlers{} sh.ServerHandler = oogws.NewServerHandler() return sh } type ServerHandlers struct { oogws.ServerHandler } // Init invoked before the server is started // If you override ths method, must call func (sh *ServerHandlers) Init(serverCTX cwf.ServerContext) error { if err := sh.ServerHandler.Init(serverCTX); nil != err { return err } return nil } func (sh *ServerHandlers) OnStart(serverCTX cwf.ServerContext) { sh.ServerHandler.OnStart(serverCTX) } 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) OnStop(serverCTX cwf.ServerContext) { sh.ServerHandler.OnStop(serverCTX) } func (sh *ServerHandlers) Validate() { sh.ServerHandler.Validate() }