From 7afd2f941f58a09c2f43ca6ff428644b2088ec0d Mon Sep 17 00:00:00 2001 From: Lyon Hill Date: Thu, 20 Feb 2014 12:56:10 -0700 Subject: [PATCH] some changes to gob. --- gob.go | 38 +++++++++++++++++++++++++++++++++----- typical curls.txt | 10 ++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 typical curls.txt diff --git a/gob.go b/gob.go index e270843..6991457 100644 --- a/gob.go +++ b/gob.go @@ -3,16 +3,44 @@ package main import ( "fmt" "net/http" - "io/ioutil" + // "io/ioutil" + "io" + "runtime" ) func handler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path) - hah, _ := ioutil.ReadAll(r.Body); - fmt.Print(string(hah)) + // hah, _ := ioutil.ReadAll(r.Body); + buf := make([]byte, 1024) + total := 0 + for { + // read a chunk + n, err := r.Body.Read(buf) + total += n + if err != nil && err != io.EOF { panic(err) } + if n == 0 { break } + + // write a chunk + // if _, err := w.Write(buf[:n]); err != nil { + // panic(err) + // } + } + fmt.Fprintf(w, "Hi there, I love %s!\n", r.URL.Path) + fmt.Fprintf(w, "thanks for all the bytes (%d)!\n", total) + + + memstats := new(runtime.MemStats) + runtime.ReadMemStats(memstats) + runtime.GC() + fmt.Println("memstats before GC: bytes = ", memstats.HeapAlloc, " footprint = ", memstats.Sys) + fmt.Println("**********") + // memstats = new(runtime.MemStats) + runtime.ReadMemStats(memstats) + fmt.Println("memstats after GC: bytes = ", memstats.HeapAlloc, " footprint = ", memstats.Sys) + + fmt.Println("len(hah)") } func main() { - http.HandleFunc("/", handler) + http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) } \ No newline at end of file diff --git a/typical curls.txt b/typical curls.txt new file mode 100644 index 0000000..2968aba --- /dev/null +++ b/typical curls.txt @@ -0,0 +1,10 @@ +post a file +curl --data @gob.go -s -X POST -H 'Transfer-Encoding: chunked' -H 'token: 1234' -T - http://localhost:8080/apps/thing + + +get a file +curl --silent -H 'token: 1234' http://bob.pagodabox.com/apps/1/builds/2/file/ + +show file (json) +curl --silent -H 'token: 1234' http://bob.pagodabox.com/apps/1/builds/2/ +