This commit is contained in:
Stephen McQuay 2014-06-06 15:41:45 -07:00
commit 46c4edbc67

65
main.go Normal file
View File

@ -0,0 +1,65 @@
package main
import (
"flag"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
"time"
)
func dump(w http.ResponseWriter, req *http.Request) {
log.Println("start")
start := time.Now()
buffer := make([]byte, 2048)
reader, err := req.MultipartReader()
if err != nil {
log.Fatal(err)
}
var part *multipart.Part
err = nil
bytesRead := 0
for err = nil; err != io.EOF; part, err = reader.NextPart() {
if err != nil {
log.Fatal(err)
}
if part != nil {
for {
n, err := part.Read(buffer)
bytesRead += n
if err == io.EOF || n == 0 {
break
}
if err != nil {
log.Fatal(err)
}
}
}
}
d := time.Since(start)
log.Printf("stop, %d bytes in %v (%f mb/s)", bytesRead, d, float64(bytesRead*8)/d.Seconds()/1e6)
}
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
flag.Parse()
port := 7777
hostname, err := os.Hostname()
if err != nil {
log.Fatal("problem getting hostname:", err)
}
log.Printf("serving on: http://%s:%d/", hostname, port)
addr := fmt.Sprintf(":%d", port)
http.HandleFunc("/", dump)
err = http.ListenAndServe(addr, nil)
if err != nil {
log.Fatal(err)
}
}