Browse Source

init

master
Stephen McQuay 8 years ago
commit
46c4edbc67
  1. 65
      main.go

65
main.go

@ -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)
}
}
Loading…
Cancel
Save