Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Feb 3, 2023
1 parent 55b57d0 commit dac3bd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
20 changes: 5 additions & 15 deletions examples/benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion internal/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}
Expand Down

0 comments on commit dac3bd1

Please sign in to comment.