Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bodokaiser/bfc43045897e44d0611b to your computer and use it in GitHub Desktop.
Save bodokaiser/bfc43045897e44d0611b to your computer and use it in GitHub Desktop.
Runtime error on stream read.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
)
func main() {
rec := httptest.NewRecorder()
req, err := http.NewRequest("POST", "/", nil)
if err != nil {
log.Fatal(err)
}
req.Write(bytes.NewBufferString("Hello"))
Handle(rec, req)
}
func Handle(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Body: %s", body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment