package server import ( 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() error { if err := sh.ServerHandler.Init(); nil != err { return err } return nil } func (sh *ServerHandlers) OnStart() { sh.ServerHandler.OnStart() } 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() { sh.ServerHandler.OnStop() } func (sh *ServerHandlers) Validate() { sh.ServerHandler.Validate() }