Standard library / net/http
http.Request.Context()
Return the request context, which is always non-nil. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (r *Request) Context() context.ContextReturn Value
context.Context
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http")
func main() { r := must(http.NewRequest("GET", "https://example.invalid/", nil)) fmt.Println(r.Context().Err() == nil)}
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) }}