initial commit

This commit is contained in:
silva guimaraes 2025-08-23 19:48:04 -03:00
commit dd48aef782
8 changed files with 1010 additions and 0 deletions

34
logging.go Normal file
View file

@ -0,0 +1,34 @@
package main
import (
"net/http"
"log"
"time"
)
type wrappedWriter struct {
http.ResponseWriter
statusCode int
}
func (w *wrappedWriter) WriteHeader(statusCode int) {
w.ResponseWriter.WriteHeader(statusCode)
w.statusCode = statusCode
}
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))
})
}