Documentation
¶
Overview ¶
Package pathshape reduces a URL path to its structural template, so /users/42/orders/550e8400-… and /users/7/orders/9b2f… are recognised as the same endpoint (/users/{int}/orders/{uuid}) while /users/me, /about-us and /blog/my-post stay distinct.
It is the one shared path normalizer: param-shape coalescing, related-record lookup (database.PathToTemplate), spitolas seed sampling, harvester and sitemap sampling, and endpoint grouping all build on it. It is a leaf package (stdlib plus pkg/mutation) so any of those can import it without a cycle.
The rules are deliberately conservative — a segment collapses only when it is a high-confidence per-record value:
- integers (including "0"/"1", which mutation.Classify calls Boolean), UUIDs, all-hex runs of ≥8 chars, ISO dates and timestamps, emails, JWTs, and base64 blobs of ≥16 chars;
- version segments (v1, v2, v10) always stay literal;
- slugs, enum-like words and anything unclassified never collapse, so /about-us and /blog/my-post keep their own shape.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type SegKind ¶
type SegKind string
SegKind is the classification of one path segment. Its string value is the placeholder name used in templates ("{int}", "{uuid}", …).
const ( Literal SegKind = "literal" // kept verbatim in the template Int SegKind = "int" // 42, 0, 1 UUID SegKind = "uuid" // 550e8400-e29b-41d4-a716-446655440000 Hex SegKind = "hex" // e3b0c442…, ≥8 hex chars Date SegKind = "date" // 2024-01-02 TS SegKind = "ts" // 2024-01-02T10:30:00Z B64 SegKind = "b64" // base64 blob, ≥16 chars Email SegKind = "email" // user@example.com JWT SegKind = "jwt" // eyJhbGciOi….….… )
func Shape ¶
Shape returns the structural template of path, e.g. "/users/{int}/orders/{uuid}", plus the kind of every non-empty segment (aligned with Segments(path)). Slashes, including leading, trailing and doubled ones, are preserved, so a path with no dynamic segment returns itself unchanged.
func (SegKind) Dynamic ¶
Dynamic reports whether a segment of this kind is normalized to a placeholder (anything but Literal).
func (SegKind) Placeholder ¶
Placeholder returns the template token for a dynamic kind ("{int}"), or "" for Literal.