Files
zeekay 795617c313 zip: the module is hanzo.ai/zip
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.
2026-08-23 21:44:55 -07:00

38 lines
824 B
Go

// sse-streaming example — Server-Sent Events via c.SendStreamWriter.
// LLM-gateway pattern: stream tokens as they arrive from upstream.
//
// go run ./examples/sse-streaming
// curl -N http://localhost:8080/v1/stream
package main
import (
"bufio"
"fmt"
"log"
"time"
"hanzo.ai/zip"
)
func main() {
app := zip.New(zip.Config{AppName: "sse-streaming"})
app.Get("/v1/stream", func(c *zip.Ctx) error {
c.SetHeader("Content-Type", "text/event-stream")
c.SetHeader("Cache-Control", "no-cache")
c.SetHeader("Connection", "keep-alive")
return c.SendStreamWriter(func(w *bufio.Writer) {
for i := 0; i < 10; i++ {
_, _ = fmt.Fprintf(w, "data: tick %d\n\n", i)
if err := w.Flush(); err != nil {
return
}
time.Sleep(200 * time.Millisecond)
}
})
})
log.Fatal(app.Listen(":8080"))
}