| package main |
| |
| import ( |
| "fmt" |
| "net/http" |
| |
| "github.com/golang/glog" |
| ) |
| |
| func handle404(w http.ResponseWriter, r *http.Request) { |
| logRequest(w, r, "404") |
| w.WriteHeader(http.StatusNotFound) |
| fmt.Fprintf(w, "404!\n") |
| } |
| |
| func handle500(w http.ResponseWriter, r *http.Request) { |
| logRequest(w, r, "500") |
| w.WriteHeader(http.StatusNotFound) |
| fmt.Fprintf(w, "500 :(\n") |
| } |
| |
| func logRequest(w http.ResponseWriter, r *http.Request, format string, args ...interface{}) { |
| result := fmt.Sprintf(format, args...) |
| glog.Infof("result: %s, remote: %q, ua: %q, referrer: %q, host: %q path: %q", result, r.RemoteAddr, r.Header.Get("User-Agent"), r.Header.Get("Referrer"), r.Host, r.URL.Path) |
| } |