Initial commit

This commit is contained in:
2024-07-25 17:23:46 +02:00
commit 59eb295c2c
28 changed files with 3870 additions and 0 deletions

30
api/middleware/logger.go Normal file
View File

@@ -0,0 +1,30 @@
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(wrapped.StatusCode, r.Method, r.URL.Path, time.Since(start))
})
}