blob: a2bd93a935c47e9e996dec624430d98b8dd63f9f [file] [log] [blame]
Sergiusz Bazanskic881cf32020-04-08 20:03:12 +02001package main
2
3import (
4 "fmt"
5 "net/http"
Sergiusz Bazanskif157b4d2020-04-10 17:39:43 +02006
7 "github.com/golang/glog"
Sergiusz Bazanskic881cf32020-04-08 20:03:12 +02008)
9
10func 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
16func 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 Bazanskif157b4d2020-04-10 17:39:43 +020021
22func 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}