Last active
October 28, 2018 17:33
-
-
Save beejjorgensen/ee17ced056144146eb09b869d274ecbf to your computer and use it in GitHub Desktop.
Super-simple logging webserver
This file contains hidden or 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 ( | |
| "log" | |
| "net/http" | |
| ) | |
| func logf(handler http.Handler) http.Handler { | |
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
| log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL) | |
| handler.ServeHTTP(w, r) | |
| }) | |
| } | |
| func main() { | |
| log.Printf("Listening on port 8000") | |
| fileServer := http.FileServer(http.Dir(".")) | |
| log.Fatal(http.ListenAndServe(":8000", logf(fileServer))) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment