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.

v0 source pure

Package realmpath is a lightweight Render.path parsing and link generation library with an idiomatic API, closely res...

Readme View source

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.

Overview

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:

Example
 1import "gno.land/p/moul/realmpath/v0"
 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}

Functions 1

func Parse

1func Parse(rawPath string) *Request
source

Parse takes a raw path string and returns a Request object. It splits the path into its components and parses any query parameters.

Types 1

type Request

struct
1type Request struct {
2	Path  string     // The path of the request
3	Query url.Values // The parsed query parameters
4	Realm string     // The realm associated with the request
5}
source

Request represents a parsed request.

Methods on Request

func PathPart

method on Request
1func (r *Request) PathPart(index int) string
source

PathPart returns the specified part of the path. If the index is out of bounds, it returns an empty string.

func PathParts

method on Request
1func (r *Request) PathParts() []string
source

PathParts returns the segments of the path as a slice of strings. It trims leading and trailing slashes and splits the path by slashes.

func String

method on Request
1func (r *Request) String() string
source

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.

Dependencies

Imports 4

/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/realmpath/v0

Imported by indexer

Source Files 4