mirror of
https://github.com/zap-proto/zip.git
synced 2026-10-19 15:38:57 +00:00
A service that keeps a legacy spelling reachable writes a two-line helper: reg(canonical, h); reg(legacy, h). hanzoai/iam has one, and it cost it the prose for NINE pairs — 18 operations — because the registration happens inside the helper, where a pass that reads `router.Get(path, handler)` calls cannot see it. Both halves published an address and silence, and the legacy half is exactly the one a consumer is likeliest to be pinned to. So the primitive moves here. zip.Alias is the same two lines, and zipdoc knows it by name — a matcher can only recognise a function whose identity it knows, which is the argument for zip owning this rather than each service rolling its own. Both addresses get the SAME sentence, because both are the same handler and mean the same thing. Deleting the legacy half when the last pinned consumer moves stays a one-word edit. Co-authored-by: Hanzo Dev <[email protected]>
27 lines
1.4 KiB
Go
27 lines
1.4 KiB
Go
package zip
|
|
|
|
// Alias registers ONE handler at TWO addresses — the canonical one and a legacy
|
|
// spelling kept reachable for consumers pinned to it.
|
|
//
|
|
// A path segment names a THING; the HTTP method says what is being done to it.
|
|
// The verb-noun addresses a service inherits (`send-verification-code`,
|
|
// `set-preferred-mfa`, …) say the verb twice, and they are what a customer reads
|
|
// in a CLI's help, in every generated SDK method name and on every docs page. The
|
|
// canonical noun is what the published document leads with; the legacy spelling
|
|
// stays reachable so nothing breaks while consumers move.
|
|
//
|
|
// One handler VALUE, two addresses: there is no second implementation to keep in
|
|
// step, and no forward that could answer differently from the thing it forwards
|
|
// to. When the last pinned consumer moves, the legacy half is deleted and nothing
|
|
// else changes.
|
|
//
|
|
// It lives here rather than in each service because cmd/zipdoc has to recognise
|
|
// it. A registration made inside a helper is invisible to a pass that reads
|
|
// router.Get(path, handler) calls, so a service that rolled its own alias helper
|
|
// silently lost the prose for BOTH addresses — the exact defect this package
|
|
// exists to prevent. Being zip's, both halves carry the handler's doc comment.
|
|
func Alias(reg func(string, ...Handler) Router, canonical, legacy string, h Handler) {
|
|
reg(canonical, h)
|
|
reg(legacy, h)
|
|
}
|