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
  • request.gnogno
    1package mux23import (4	"net/url"5	"strings"6)78// Request represents an incoming request.9type Request struct {10	// Path is request path name.11	//12	// Note: use RawPath to obtain a raw path with query string.13	Path string1415	// RawPath contains a whole request path, including query string.16	RawPath string1718	// HandlerPath is handler rule that matches a request.19	HandlerPath string2021	// Query contains the parsed URL query parameters.22	Query url.Values23}2425// GetVar retrieves a variable from the path based on routing rules.26func (r *Request) GetVar(key string) string {27	handlerParts := strings.Split(r.HandlerPath, "/")28	reqParts := strings.Split(r.Path, "/")29	reqIndex := 030	for handlerIndex := 0; handlerIndex < len(handlerParts); handlerIndex++ {31		handlerPart := handlerParts[handlerIndex]32		switch {33		case handlerPart == "*":34			// If a wildcard "*" is found, consume all remaining segments35			wildcardParts := reqParts[reqIndex:]36			reqIndex = len(reqParts)                // Consume all remaining segments37			return strings.Join(wildcardParts, "/") // Return all remaining segments as a string38		case strings.HasPrefix(handlerPart, "{") && strings.HasSuffix(handlerPart, "}"):39			// If a variable of the form {param} is found we compare it with the key40			parameter := handlerPart[1 : len(handlerPart)-1]41			if parameter == key {42				return reqParts[reqIndex]43			}44			reqIndex++45		default:46			if reqIndex >= len(reqParts) || handlerPart != reqParts[reqIndex] {47				return ""48			}49			reqIndex++50		}51	}5253	return ""54}55

    Functions

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

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