From afb17649051db4d0da6f0e499ec27738962a71ff Mon Sep 17 00:00:00 2001 From: Ola <1386739+olahol@users.noreply.github.com> Date: Sat, 19 Nov 2022 18:28:27 +0100 Subject: [PATCH] Update README --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index dc96d53..c43d605 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,34 @@ go get github.com/olahol/melody [![Chat](https://cdn.rawgit.com/olahol/melody/master/examples/chat/demo.gif "Demo")](https://github.com/olahol/melody/tree/master/examples/chat) +```go +package main + +import ( + "net/http" + + "github.com/olahol/melody" +) + +func main() { + m := melody.New() + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "index.html") + }) + + http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { + m.HandleRequest(w, r) + }) + + m.HandleMessage(func(s *melody.Session, msg []byte) { + m.Broadcast(msg) + }) + + http.ListenAndServe(":5000", nil) +} +``` + Using [Gin](https://github.com/gin-gonic/gin): ```go package main