PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/nt/mux/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
nt / mux
Files
10 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/nt/mux/v0
gno
0.9

Files (10)

  • README.mdmarkdown
  • gnomod.tomltoml
  • doc.gnogno
  • handler.gnogno
  • helpers.gnogno
  • request.gnogno
  • response.gnogno
  • router.gnogno
  • request_test.gnogno
  • router_test.gnogno
  • doc.gnogno
    1// v0 - Unaudited: This is an initial version that has not yet been formally audited.2// A fully audited version will be published as a subsequent release.3// Use in production at your own risk.4//5// Package mux provides a simple routing and rendering library for handling dynamic path-based requests in Gno contracts.6//7// The `mux` package aims to offer similar functionality to `http.ServeMux` in Go, but for Gno's Render() requests.8// It allows you to define routes with dynamic parts and associate them with corresponding handler functions for rendering outputs.9//10// Usage:11// 1. Create a new Router instance using `NewRouter()` to handle routing and rendering logic.12// 2. Register routes and their associated handler functions using the `Handle(route, handler)` method.13// 3. Implement the rendering logic within the handler functions, utilizing the `Request` and `ResponseWriter` types.14// 4. Use the `Render(path)` method to process a given path and execute the corresponding handler function to obtain the rendered output.15//16// Route Patterns:17// Routes can include dynamic parts enclosed in braces, such as "users/{id}" or "hello/{name}". The `Request` object's `GetVar(key)`18// method allows you to extract the value of a specific variable from the path based on routing rules.19//20// Example:21//22//	router := mux.NewRouter()23//24//	// Define a route with a variable and associated handler function25//	router.HandleFunc("hello/{name}", func(res *mux.ResponseWriter, req *mux.Request) {26//		name := req.GetVar("name")27//		if name != "" {28//			res.Write("Hello, " + name + "!")29//		} else {30//			res.Write("Hello, world!")31//		}32//	})33//34//	// Render the output for the "/hello/Alice" path35//	output := router.Render("hello/Alice")36//	// Output: "Hello, Alice!"37//38// Note: The `mux` package provides a basic routing and rendering mechanism for simple use cases. For more advanced routing features,39// consider using more specialized libraries or frameworks.40package mux41

    Functions

    not supported for pure packages by the node (vm/qfuncs)

    Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.