commit inicial

This commit is contained in:
silva guimaraes 2025-07-03 17:12:05 -03:00
commit 92b0a902ca
20 changed files with 2464 additions and 0 deletions

32
logging.go Normal file
View file

@ -0,0 +1,32 @@
package main
import (
"log"
"net/http"
"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.Printf("%v %5v %12v %v", wrapped.statusCode, r.Method, time.Since(start), r.URL.Path)
})
}