1
0
mirror of https://github.com/labstack/echo.git synced 2025-04-02 22:05:34 +02:00
echo/recipes/websocket/server.go

34 lines
538 B
Go
Raw Normal View History

package main
import (
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
"golang.org/x/net/websocket"
)
func main() {
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Static("/", "public")
e.WebSocket("/ws", func(c *echo.Context) (err error) {
ws := c.Socket()
msg := ""
for {
if err = websocket.Message.Send(ws, "Hello, Client!"); err != nil {
return
}
if err = websocket.Message.Receive(ws, &msg); err != nil {
return
}
println(msg)
}
return
})
e.Run(":1323")
}