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

43 lines
1.3 KiB
Go

// migrate-from-chi example — chi → zip via stdlib adapter.
//
// Use zip.AdaptNetHTTP(chiRouter) to mount an existing chi.Router as a
// migration step. Replace adapted routes with native zip handlers when
// feasible; the adapter costs ~5% perf vs native Fiber dispatch.
//
// chi is NOT a dep of this example — we adapt any http.Handler, and a
// chi.Router satisfies that interface natively.
package main
import (
"log"
"net/http"
"hanzo.ai/zip"
"hanzo.ai/zip/middleware"
)
// legacyHandler stands in for an existing chi.Router. Same shape
// (http.Handler) so zip.AdaptNetHTTP works without changes.
type legacyHandler struct{}
func (legacyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"legacy":true}`))
}
func main() {
app := zip.New(zip.Config{AppName: "migrate-from-chi"})
app.Use(middleware.Recover())
// Native zip routes for new work.
app.Get("/v1/users/:id", func(c *zip.Ctx) error {
return c.JSON(200, map[string]string{"id": c.Param("id")})
})
// Mount the legacy chi router under /legacy/chi for incremental
// migration. Replace one path at a time with native zip handlers.
app.Mount("/legacy/chi", legacyHandler{})
log.Fatal(app.Listen(":8080"))
}