package server import ( "context" "git.loafle.net/commons_go/config" "github.com/valyala/fasthttp" "go.uber.org/zap" ogw "git.loafle.net/overflow/overflow_gateway_websocket" ) type serverHandlers struct { ogw.ServerHandlers ctx context.Context logger *zap.Logger cfg config.Configurator } func (sh *serverHandlers) OnConnection(soc ogw.Socket) { sh.logger.Info("connect", zap.String("path", soc.Path()), zap.String("id", soc.ID()), ) } func (sh *serverHandlers) OnDisconnected(soc ogw.Socket) { sh.logger.Info("disconnect", zap.String("path", soc.Path()), zap.String("id", soc.ID()), ) } func (sh *serverHandlers) OnCheckOrigin(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) { }