Created
May 26, 2015 19:00
-
-
Save russmack/9b1ef3c4e1613aa9c5eb to your computer and use it in GitHub Desktop.
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
// Author: Kyle Lemons | |
package main | |
import ( | |
"fmt" | |
"http" | |
"log" | |
) | |
func Log(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() { | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:]) | |
}) | |
http.ListenAndServe(":80", Log(http.DefaultServeMux)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment