Standard library / net/http
http.Request.SetPathValue()
Sets a named path value on a request, including values supplied by custom routers. Expected stdout: '7\n'.
Formal Syntax & Structure
go syntaxgo
func (r *Request) SetPathValue(name, value string)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Name of the requested cookie or field. |
| value | string | Value to store. |
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http/httptest")
func main() { r := httptest.NewRequest("GET", "/", nil) r.SetPathValue("id", "7") fmt.Println(r.PathValue("id"))}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}