Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lixizan committed Apr 22, 2023
1 parent 0fcd170 commit a31c3de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 3 additions & 21 deletions examples/server/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"github.com/lxzan/gws"
"log"
"net/http"
Expand All @@ -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())
}

0 comments on commit a31c3de

Please sign in to comment.