2020-04-08 18:03:12 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2020-04-10 15:39:43 +00:00
|
|
|
|
|
|
|
"github.com/golang/glog"
|
2020-04-08 18:03:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2020-04-10 15:39:43 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|