add echo example
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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"))
|
||||
}
|
||||
Reference in New Issue
Block a user