diff --git a/README.md b/README.md index 07ece6a..b48cf49 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ 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) +Using [Gin](https://github.com/gin-gonic/gin): ```go package main @@ -54,6 +55,43 @@ func main() { } ``` +Using [Echo](https://github.com/labstack/echo): +```go +package main + +import ( + "github.com/labstack/echo" + "github.com/labstack/echo/engine/standard" + "github.com/labstack/echo/middleware" + "github.com/olahol/melody" + "net/http" +) + +func main() { + e := echo.New() + m := melody.New() + + e.Use(middleware.Logger()) + e.Use(middleware.Recover()) + + e.GET("/", func(c echo.Context) error { + http.ServeFile(c.Response().(*standard.Response).ResponseWriter, c.Request().(*standard.Request).Request, "index.html") + return nil + }) + + e.GET("/ws", func(c echo.Context) error { + m.HandleRequest(c.Response().(*standard.Response).ResponseWriter, c.Request().(*standard.Request).Request) + return nil + }) + + m.HandleMessage(func(s *melody.Session, msg []byte) { + m.Broadcast(msg) + }) + + e.Run(standard.New(":5000")) +} +``` + ## [Example: gophers](https://github.com/olahol/melody/tree/master/examples/gophers) [![Gophers](https://cdn.rawgit.com/olahol/melody/master/examples/gophers/demo.gif "Demo")](https://github.com/olahol/melody/tree/master/examples/gophers) diff --git a/examples/chat-echo/index.html b/examples/chat-echo/index.html new file mode 100644 index 0000000..eac2a95 --- /dev/null +++ b/examples/chat-echo/index.html @@ -0,0 +1,50 @@ + +
+