Standard library / net/http/httptest
httptest.NewRecorder()
Creates an initialized response recorder for direct handler tests. Expected stdout: '200 hello\n'.
Formal Syntax & Structure
go syntaxgo
func NewRecorder() *ResponseRecorderReturn Value
*ResponseRecorder
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http/httptest")
func main() { w := httptest.NewRecorder() fmt.Fprint(w, "hello") fmt.Println(w.Result().StatusCode, w.Body.String())}
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) }}