Skip to content

Commit

Permalink
http mode
Browse files Browse the repository at this point in the history
  • Loading branch information
bmizerany committed Dec 14, 2011
1 parent 7cb7da0 commit e48d094
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion main.go
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"net"
"net/http"
"sync"
"time"
)
Expand All @@ -31,6 +32,7 @@ var (
did = flag.Int64("d", 0, "datacenter id")
laddr = flag.String("l", "0.0.0.0:4444", "the address to listen on")
lts = flag.Int64("t", -1, "the last timestamp in milliseconds")
httpmode = flag.Bool("http", false, "run in http mode")
)

var (
Expand All @@ -40,7 +42,12 @@ var (

func main() {
parseFlags()
acceptAndServe(mustListen())
l := mustListen()
if *httpmode {
acceptAndServeHTTP(l)
} else {
acceptAndServe(l)
}
}

func parseFlags() {
Expand All @@ -62,6 +69,14 @@ func mustListen() net.Listener {
return l
}

func acceptAndServeHTTP(l net.Listener) {
m := http.NewServeMux()
m.HandleFunc("/g", func(w http.ResponseWriter, r *http.Request) {
serve(r.Body, w)
})
http.Serve(l, m)
}

func acceptAndServe(l net.Listener) {
for {
cn, err := l.Accept()
Expand Down

0 comments on commit e48d094

Please sign in to comment.