From dac3bd1f19fd3e3eaba9f887fc144baf1c1501ca Mon Sep 17 00:00:00 2001 From: lixizan Date: Fri, 3 Feb 2023 22:33:25 +0800 Subject: [PATCH] fix --- examples/benchmark/main.go | 20 +++++--------------- internal/error.go | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/examples/benchmark/main.go b/examples/benchmark/main.go index 7a426db2..14f83348 100644 --- a/examples/benchmark/main.go +++ b/examples/benchmark/main.go @@ -6,8 +6,9 @@ import ( ) func main() { - var handler = new(WebSocket) - var upgrader = gws.NewUpgrader(gws.WithEventHandler(handler)) + var upgrader = gws.NewUpgrader( + gws.WithEventHandler(new(WebSocket)), + ) http.HandleFunc("/connect", func(writer http.ResponseWriter, request *http.Request) { socket, err := upgrader.Accept(writer, request) if err != nil { @@ -19,21 +20,10 @@ func main() { _ = http.ListenAndServe(":3000", nil) } -type WebSocket struct{} - -func (c *WebSocket) OnClose(socket *gws.Conn, code uint16, reason []byte) { -} - -func (c *WebSocket) OnError(socket *gws.Conn, err error) { +type WebSocket struct { + gws.BuiltinEventEngine } -func (c *WebSocket) OnOpen(socket *gws.Conn) { -} - -func (c *WebSocket) OnPing(socket *gws.Conn, payload []byte) {} - -func (c *WebSocket) OnPong(socket *gws.Conn, payload []byte) {} - func (c *WebSocket) OnMessage(socket *gws.Conn, message *gws.Message) { socket.WriteMessage(message.Typ(), message.Bytes()) message.Close() diff --git a/internal/error.go b/internal/error.go index a2169fd4..e0ccb9e8 100644 --- a/internal/error.go +++ b/internal/error.go @@ -79,7 +79,7 @@ func (c StatusCode) Uint16() uint16 { func (c StatusCode) Bytes() []byte { if c == 0 { - return []byte{0, 0} + return []byte{} } return []byte{uint8(c >> 8), uint8(c << 8 >> 8)} }