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

realmpath source pure

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

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"
 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.

Imports 4

  • chain/runtime stdlib
  • chain/runtime/unsafe stdlib
  • net/url stdlib
  • strings stdlib

Source Files 3