Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

README.md

2.20 Kb · 61 lines

gno.land/p/moul/realmpath

Parse the path argument that Render receives, with an API shaped like net/url, and rebuild a URL from it.

 1func Render(path string) string {          // path = "hello/world?foo=bar"
 2	req := realmpath.Parse(path)
 3
 4	req.Path             // "hello/world"
 5	req.PathPart(0)      // "hello"
 6	req.PathPart(1)      // "world"
 7	req.Query.Get("foo") // "bar"
 8
 9	req.String()         // "/r/current/realm:hello/world?foo=bar"
10}

That is the whole surface: Parse, PathParts, PathPart(i), Query (a real url.Values), and String.

PathPart is bounds-checked and returns "" for an index that is not there, so routing reads as a plain switch with no length guards:

1switch req.PathPart(0) {
2case "":      return renderIndex(req)
3case "posts": return renderPost(req.PathPart(1))
4default:      return "404"
5}

String() fills Realm from the current realm when it is unset, which is what makes pagination and filter links survive the realm being moved or versioned.

One security note, worth reading before you trust req.Realm

The package doc carries it in full. In short: String() lazily fills r.Realm from unsafe.CurrentRealm() inside a non-crossing /p/ method, which walks past non-crossing frames to the most recent crossing ancestor rather than the immediate caller. Under a contrived call chain, r.Realm is not a reliable identity claim.

That is accepted here because r.Realm is only ever consumed as a display string. If you add a consumer that gates a write or an authorization decision on r.Realm, do not: set req.Realm = cur.PkgPath() explicitly from the caller under rlm.IsCurrent() instead.

Going the other way, from a route to a link, is p/moul/txlink.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.