Skip to content

Instantly share code, notes, and snippets.

@russmack
Created May 26, 2015 19:00
Show Gist options
  • Save russmack/9b1ef3c4e1613aa9c5eb to your computer and use it in GitHub Desktop.
Save russmack/9b1ef3c4e1613aa9c5eb to your computer and use it in GitHub Desktop.
// 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