Files
zeekayandHanzo Dev 5f71d2496b The router is three nouns, and every one of them is concrete
App, Group, Operation. A group is a prefix and what holds under it, an operation
is one typed route declared there, and the verb methods are generic methods —
which Go 1.27 allows on a concrete type and still refuses on an interface. So In
and Out come from the handler and the caller writes no type arguments:

	users := app.Group("/v1/users")
	users.Post("/", api.Create)

	mint := users.Group("/mint").With(middleware.Mint(gate))
	mint.Post("/deposit", api.Deposit)

A Group is a CLOSED HANDLE: two unexported fields, and no method that hands back
the app, the parent or the fiber underneath. A subsystem given the group at its
own prefix cannot reach above it, so confinement is a property of the type
instead of a rule something has to police — which is what a host needs in order
to hand out a bounded surface and know what comes back.

That is bought by giving up the router interface, deliberately. Router and
OpTarget are gone, and with them the ability to implement a route table outside
this package: a decorator is no longer a router, a gate is middleware on a group,
and a bound is a path. The five package-level verb functions go the same way —
a registration is a method on the thing it registers into.

Raw carries what is not a typed operation: a stream, an upgrade, a probe, a
foreign subtree. It names its method, and it is the longer spelling because
opting out of the typed model is the exception and should read like one.



Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 01:39:17 -07:00

64 lines
1.9 KiB
Go

// migrate-from-beego example — beego → zip migration via http.Handler
// adapter. beego.BeeApp exposes Handlers as an http.Handler-compatible
// surface; the same AdaptNetHTTP adapter that fronted chi handles beego too.
//
// In a real port:
//
// import (
// "github.com/beego/beego/v2/server/web"
// "github.com/zap-proto/zip"
// )
//
// beeApp := web.NewHttpSever() // your existing beego app
// zipApp := zip.New(zip.Config{AppName: "iam"})
// zipApp.Group("/legacy/iam").All("/*", zip.AdaptNetHTTP(beeApp.Handlers))
//
// This example uses a stand-in http.Handler so the file builds without
// pulling beego — same adapter pattern in either case.
//
// The adapted subtree is a wildcard route and registers no operation, so nothing
// behind /legacy/iam is in the OpenAPI document, the MCP tool list, the CLI or
// the call plane. New work goes in as a TYPED op, and a native route added later
// wins by specificity — so the legacy tree shrinks one op at a time.
package main
import (
"context"
"log"
"net/http"
"github.com/zap-proto/zip"
)
type beegoStub struct{}
func (beegoStub) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"legacy_beego":true}`))
}
// Health is what the probe answers.
type Health struct {
Status string `json:"status"`
}
// Nothing is an operation that takes no input.
type Nothing struct{}
// Healthz reports whether IAM is up.
func healthz(context.Context, *Nothing) (*Health, error) {
return &Health{Status: "ok"}, nil
}
func main() {
app := zip.New(zip.Config{AppName: "migrate-from-beego"})
// New native zip routes, typed:
app.Get("/v1/iam/healthz", healthz)
// Legacy beego app under /legacy/iam — one adapted wildcard route:
app.Group("/legacy/iam").Raw(zip.MethodAll, "/*", zip.AdaptNetHTTP(beegoStub{}))
log.Fatal(app.Listen("http://:8080"))
}