Created
August 4, 2015 15:11
-
-
Save berryp/796152ed2a1e5ef089c3 to your computer and use it in GitHub Desktop.
Super simple http file server tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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