From a31c3deda206c79b7305d734ce4b0a306adb5c5b Mon Sep 17 00:00:00 2001 From: lixizan Date: Sat, 22 Apr 2023 08:26:04 +0800 Subject: [PATCH] update docs --- README.md | 2 +- examples/server/server.go | 24 +++--------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index de563208..9473d1e3 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ type Event interface { #### Examples - [chat room](examples/chatroom/main.go) -- [echo](examples/testsuite/main.go) +- [echo](examples/server/server.go) #### Server diff --git a/examples/server/server.go b/examples/server/server.go index c902e2bf..76a66d2d 100644 --- a/examples/server/server.go +++ b/examples/server/server.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "github.com/lxzan/gws" "log" "net/http" @@ -25,27 +24,10 @@ func main() { } type Websocket struct { -} - -func (w Websocket) OnOpen(socket *gws.Conn) { - _ = socket.WriteString("hello, there is server") -} - -func (w Websocket) OnError(socket *gws.Conn, err error) { - fmt.Printf("onerror: err=%s\n", err.Error()) -} - -func (w Websocket) OnClose(socket *gws.Conn, code uint16, reason []byte) { - fmt.Printf("onclose: code=%d, payload=%s\n", code, string(reason)) -} - -func (w Websocket) OnPing(socket *gws.Conn, payload []byte) { -} - -func (w Websocket) OnPong(socket *gws.Conn, payload []byte) { - socket.WritePong(payload) + gws.BuiltinEventHandler } func (w Websocket) OnMessage(socket *gws.Conn, message *gws.Message) { - fmt.Printf("recv: %s\n", message.Data.String()) + defer message.Close() + _ = socket.WriteMessage(message.Opcode, message.Bytes()) }