Files
commerce/util/hashid/http/http.go
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

39 lines
806 B
Go

package http
import (
"net/http"
"github.com/zap-proto/zip"
"github.com/hanzoai/commerce/util/hashid"
"github.com/hanzoai/commerce/util/template"
)
func decodeKey(c *zip.Ctx) error {
ctx := c.Context()
id := c.Param("id")
key, err := hashid.DecodeKey(ctx, id)
if err != nil {
panic(err)
}
return template.Render(c, "hashid.html",
"id", id,
"namespace", key.Namespace(),
"kind", key.Kind(),
"parent", key.Parent(),
"intid", key.IntID(),
)
}
// Setup handlers for HTTP registered tasks
func SetupRoutes(router *zip.Group) {
// Redirects
router.Raw(http.MethodGet, "/hashid", func(c *zip.Ctx) error {
return template.Render(c, "hashid.html")
})
// Check a hashid
router.Raw(http.MethodGet, "/hashid/:id", decodeKey)
router.Raw(http.MethodPost, "/hashid/:id", decodeKey)
}