package main import ( "fmt"; "net/http"; "net/http/httptest" ) func helloHandler(w http.ResponseWriter, r *http.Request) { // TODO: write Hello, Go! to w } func main() { req, _ := http.NewRequest("GET", "/", nil) rec := httptest.NewRecorder() helloHandler(rec, req) fmt.Println("Status:", rec.Code) fmt.Println("Body:", rec.Body.String()) }
Output
Click Run to execute, or Check to validate.
Ask questions or share tips about this tutorial
Sign in to join the discussion