mirror of
https://github.com/justinian/menagerie.git
synced 2025-12-11 00:54:33 -08:00
Partially copied from justinian/ark, updated to be a single process that watches save files and updates a single sqlite3 database.
25 lines
661 B
Go
25 lines
661 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
type statusSaver struct {
|
|
s int
|
|
w http.ResponseWriter
|
|
}
|
|
|
|
func (s *statusSaver) Status() int { return s.s }
|
|
func (s *statusSaver) Header() http.Header { return s.w.Header() }
|
|
func (s *statusSaver) Write(b []byte) (int, error) { return s.w.Write(b) }
|
|
func (s *statusSaver) WriteHeader(c int) { s.s = c; s.w.WriteHeader(c) }
|
|
|
|
func loggingWrapper(h http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
s := statusSaver{s: 200, w: w}
|
|
h.ServeHTTP(&s, r)
|
|
log.Printf("%21s %3d%7s %s", r.RemoteAddr, s.Status(), r.Method, r.URL)
|
|
})
|
|
}
|