Files
zip/examples/sse-streaming/main.go
T
zeekay c581e0af7b feat: zip canonical home — the ZAP-native web framework, consolidated
zip is shared protocol infra (the fiber-over-ZAP web framework used by every
Lux/Hanzo/Zoo Go binary — nodes, gateway, cloud, iam, kms, o11y, ai, …), so its
home is the ZAP protocol family (zap-proto/{go,http,zapd,zip}), NOT any one org's
brand namespace. This consolidates the rich framework (formerly hanzoai/zip v0.5.0
— Ctx/Handler/Errorf/Err*/HTTPError, typed handlers, middleware, runtime/extension
loading, openapi, validate, zaprpc) with the real ZAP transport (ListenZAP/
ListenHTTP/Serve over zap-proto/http) into ONE canonical module.

Module path github.com/hanzoai/zip -> github.com/zap-proto/zip. Code identical to
hanzoai/zip v0.5.0; promoted to v1.0.0 as the stable shared-infra framework. The
prior hanzoai/zip lineage is retired — one home, one import path, one way.

Verified: go build/vet/test ./... green; the ZAP round-trip integration test serves
/v1/health over the real ZAP transport (200 + handler JSON).
2026-07-01 23:08:35 -07:00

38 lines
840 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"
"github.com/zap-proto/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.ListenHTTP(":8080"))
}