diff --git a/server.go b/server.go index a0d173c..1ae02c2 100644 --- a/server.go +++ b/server.go @@ -1,7 +1,6 @@ package overflow_gateway_websocket import ( - "log" "net/http" "sync" @@ -43,12 +42,11 @@ func NewServer(o *ServerOptions) Server { return s } -func (s *server) onPush(cb OnPushFunc) { - -} - func (s *server) onError(ctx *fasthttp.RequestCtx, status int, reason error) { + ctx.Response.Header.Set("Sec-Websocket-Version", "13") + ctx.Error(http.StatusText(status), status) + s._option.OnError(ctx, status, reason) } func (s *server) onDisconnected(c Client) { @@ -61,16 +59,13 @@ func (s *server) onConnection(ctx *fasthttp.RequestCtx) { path := string(ctx.Path()) co, ok := s._handlers[path] if !ok { - ctx.Response.Header.Set("Sec-Websocket-Version", "13") - ctx.Error(http.StatusText(fasthttp.StatusNotFound), fasthttp.StatusNotFound) - - log.Printf("Path[%s] is not exist.", path) + s.onError(ctx, fasthttp.StatusNotFound, nil) return } s._upgrader.Upgrade(ctx, nil, func(conn *websocket.Conn, err error) { if err != nil { - log.Print("upgrade:", err) + s.onError(ctx, fasthttp.StatusInternalServerError, err) return } s._cMtx.Lock() diff --git a/server_options.go b/server_options.go index 3153cd7..8b29372 100644 --- a/server_options.go +++ b/server_options.go @@ -10,7 +10,6 @@ import ( type ( OnConnectionFunc func(c Client) OnDisconnectedFunc func(c Client) - OnPushFunc func() ) const (