Sergiusz Bazanski | c881cf3 | 2020-04-08 20:03:12 +0200 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
Sergiusz Bazanski | f157b4d | 2020-04-10 17:39:43 +0200 | [diff] [blame] | 6 | |
| 7 | "github.com/golang/glog" |
Sergiusz Bazanski | c881cf3 | 2020-04-08 20:03:12 +0200 | [diff] [blame] | 8 | ) |
| 9 | |
| 10 | func handle404(w http.ResponseWriter, r *http.Request) { |
| 11 | logRequest(w, r, "404") |
| 12 | w.WriteHeader(http.StatusNotFound) |
| 13 | fmt.Fprintf(w, "404!\n") |
| 14 | } |
| 15 | |
| 16 | func handle500(w http.ResponseWriter, r *http.Request) { |
| 17 | logRequest(w, r, "500") |
| 18 | w.WriteHeader(http.StatusNotFound) |
| 19 | fmt.Fprintf(w, "500 :(\n") |
| 20 | } |
Sergiusz Bazanski | f157b4d | 2020-04-10 17:39:43 +0200 | [diff] [blame] | 21 | |
| 22 | func logRequest(w http.ResponseWriter, r *http.Request, format string, args ...interface{}) { |
| 23 | result := fmt.Sprintf(format, args...) |
| 24 | 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) |
| 25 | } |