func Parse
Parse takes a raw path string and returns a Request object. It splits the path into its components and parses any query parameters.
Package realmpath is a lightweight Render.path parsing and link generation library with an idiomatic API, closely res...
Package realmpath is a lightweight Render.path parsing and link generation library with an idiomatic API, closely resembling that of net/url.
This package provides utilities for parsing request paths and query parameters, allowing you to extract path segments and manipulate query values.
Example usage:
1import "gno.land/p/moul/realmpath"
2
3func Render(path string) string {
4 // Parsing a sample path with query parameters
5 path = "hello/world?foo=bar&baz=foobar"
6 req := realmpath.Parse(path)
7
8 // Accessing parsed path and query parameters
9 println(req.Path) // Output: hello/world
10 println(req.PathPart(0)) // Output: hello
11 println(req.PathPart(1)) // Output: world
12 println(req.Query.Get("foo")) // Output: bar
13 println(req.Query.Get("baz")) // Output: foobar
14
15 // Rebuilding the URL
16 println(req.String()) // Output: /r/current/realm:hello/world?baz=foobar&foo=bar
17}
Request represents a parsed request.
PathPart returns the specified part of the path. If the index is out of bounds, it returns an empty string.
PathParts returns the segments of the path as a slice of strings. It trims leading and trailing slashes and splits the path by slashes.
String rebuilds the URL from the path and query values. If the Realm is not set, it automatically retrieves the current realm path.
SECURITY (Class-2-shaped, intentionally accepted): unsafe.CurrentRealm() inside a non-crossing /p/ method is .Title()-vulnerable — it walks past non-crossing frames to the most-recent crossing ancestor, not the immediate caller. The lazily-captured r.Realm is therefore NOT a reliable identity claim under a contrived call chain.
This is acceptable here because r.Realm is consumed only as a URL string for rendering (the line below builds reconstructedPath for display); no caller in /examples uses it for authorization. If you add a new consumer that gates writes/auth on r.Realm, replace the lazy fill with an explicit `req.Realm = cur.PkgPath()` set by the caller under rlm.IsCurrent(), or switch to a sibling method that takes a realm parameter — see docs/resources/gno-security.md for the threat-class taxonomy.