Skip to content

Instantly share code, notes, and snippets.

@berryp
Created August 4, 2015 15:11
Show Gist options
  • Save berryp/796152ed2a1e5ef089c3 to your computer and use it in GitHub Desktop.
Save berryp/796152ed2a1e5ef089c3 to your computer and use it in GitHub Desktop.
Super simple http file server tool
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
func LogHandler(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s %s\n", r.RemoteAddr, r.Method, r.URL)
handler.ServeHTTP(w, r)
})
}
func main() {
port := flag.Int("port", 5000, "")
flag.Parse()
fs := http.FileServer(http.Dir("."))
http.Handle("/", LogHandler(fs))
log.Println("Listening...")
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", *port), nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment