Standard library / net/http
http.NotFound()
Writes a standard 404 response. Call before writing any final status. Expected stdout: '404\n'.
Formal Syntax & Structure
go syntaxgo
func NotFound(w ResponseWriter, r *Request)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| w | ResponseWriter | Destination writer. |
| r | *Request | Source reader. |
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http" "net/http/httptest")
func main() { w := httptest.NewRecorder() http.NotFound(w, httptest.NewRequest("GET", "/", nil)) fmt.Println(w.Code)}
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) }}