2013-10-21 13:45:14 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-10-21 19:21:59 -07:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2013-10-21 13:45:14 -07:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2013-10-21 19:21:59 -07:00
|
|
|
var port = flag.Int("port", 8000, "port from which to serve")
|
|
|
|
|
2013-10-21 13:45:14 -07:00
|
|
|
func logger(h http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
log.Printf("%s: %s\n", r.RemoteAddr, r.URL)
|
|
|
|
h.ServeHTTP(w, r)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2013-10-21 19:21:59 -07:00
|
|
|
flag.Parse()
|
|
|
|
addr := fmt.Sprintf(":%d", *port)
|
2013-10-21 13:45:14 -07:00
|
|
|
fh := http.FileServer(http.Dir("./"))
|
|
|
|
http.ListenAndServe(":8080", logger(fh))
|
2013-10-21 19:21:59 -07:00
|
|
|
if err := http.ListenAndServe(addr, logger(fh)); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2013-10-21 13:45:14 -07:00
|
|
|
}
|