mirror of
https://github.com/hanzoai/zip.git
synced 2026-10-30 20:11:40 +00:00
The import path a reader types is the one the org owns, rather than the forge that happens to host the bytes. hanzo.ai serves the go-import meta and points it at the same repository, so where the code lives does not change. The README's `go get` line moves with it — an install instruction naming the old path is the one leftover a reader would actually follow.
35 lines
675 B
Go
35 lines
675 B
Go
// websocket example — chat-style echo server.
|
|
//
|
|
// go run ./examples/websocket
|
|
// wscat -c ws://localhost:8080/ws
|
|
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"hanzo.ai/zip"
|
|
"hanzo.ai/zip/middleware"
|
|
"hanzo.ai/zip/wsx"
|
|
)
|
|
|
|
func main() {
|
|
app := zip.New(zip.Config{AppName: "websocket"})
|
|
app.Use(middleware.Recover(), middleware.RequestID())
|
|
|
|
app.Get("/ws", wsx.Upgrade(func(c *wsx.Conn) error {
|
|
log.Printf("ws connection from %s", c.RemoteAddr())
|
|
for {
|
|
mt, msg, err := c.ReadMessage()
|
|
if err != nil {
|
|
log.Printf("ws read: %v", err)
|
|
return err
|
|
}
|
|
if err := c.WriteMessage(mt, msg); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}))
|
|
|
|
log.Fatal(app.Listen(":8080"))
|
|
}
|