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}55Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.