All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 46s
31 lines
590 B
Go
31 lines
590 B
Go
package middleware
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type WrappedWriter struct {
|
|
http.ResponseWriter
|
|
StatusCode int
|
|
}
|
|
|
|
func (w *WrappedWriter) WriteHeader(code int) {
|
|
w.ResponseWriter.WriteHeader(code)
|
|
w.StatusCode = code
|
|
}
|
|
|
|
func Logging(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
start := time.Now()
|
|
|
|
wrapped := &WrappedWriter{
|
|
ResponseWriter: w,
|
|
StatusCode: http.StatusOK,
|
|
}
|
|
next.ServeHTTP(wrapped, r)
|
|
log.Println(r.RemoteAddr, wrapped.StatusCode, r.Method, r.URL.Path, time.Since(start))
|
|
})
|
|
}
|