Skip to content

Commit

Permalink
some changes to gob.
Browse files Browse the repository at this point in the history
  • Loading branch information
lyondhill committed Feb 20, 2014
1 parent 684adee commit 7afd2f9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
38 changes: 33 additions & 5 deletions gob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 10 additions & 0 deletions typical curls.txt
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 7afd2f9

Please sign in to comment.