Go-Backend (chi, pgx, golang-migrate) + React/TS-Frontend als PWA. Enthalten: Auth inkl. OIDC, Dateien mit Versionen und Papierkorb, Freigaben (Links + intern), WebDAV, Gruppenordner, Admin/Theming, Volltextsuche mit OCR, eigener PDF-Betrachter und WOPI-Office (Collabora/OnlyOffice). Nicht im Repo: deploy/.env (Sitzungsschlüssel, DB- und Admin-Passwort) sowie alle Daten- und Build-Verzeichnisse – siehe .gitignore. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
44 lines
859 B
Go
44 lines
859 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/rs/zerolog"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func Logger(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
start := time.Now()
|
|
ww := &responseWriter{ResponseWriter: w, status: http.StatusOK}
|
|
|
|
next.ServeHTTP(ww, r)
|
|
|
|
level := zerolog.InfoLevel
|
|
if ww.status >= 500 {
|
|
level = zerolog.ErrorLevel
|
|
} else if ww.status >= 400 {
|
|
level = zerolog.WarnLevel
|
|
}
|
|
|
|
log.WithLevel(level).
|
|
Str("method", r.Method).
|
|
Str("path", r.URL.Path).
|
|
Int("status", ww.status).
|
|
Dur("duration", time.Since(start)).
|
|
Str("ip", r.RemoteAddr).
|
|
Msg("")
|
|
})
|
|
}
|
|
|
|
type responseWriter struct {
|
|
http.ResponseWriter
|
|
status int
|
|
}
|
|
|
|
func (rw *responseWriter) WriteHeader(status int) {
|
|
rw.status = status
|
|
rw.ResponseWriter.WriteHeader(status)
|
|
}
|