mirror of
				https://github.com/3ybactuk/marketplace-go-service-project.git
				synced 2025-10-31 14:33:45 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			27 lines
		
	
	
		
			453 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			453 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package middlewares
 | |
| 
 | |
| import (
 | |
| 	"net/http"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/rs/zerolog/log"
 | |
| )
 | |
| 
 | |
| type TimerMiddleware struct {
 | |
| 	h http.Handler
 | |
| }
 | |
| 
 | |
| func NewTimerMiddleware(h http.Handler) http.Handler {
 | |
| 	return &TimerMiddleware{
 | |
| 		h: h,
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (m *TimerMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 | |
| 	defer func(now time.Time) {
 | |
| 		log.Debug().Msgf("%s %s spent %s", r.Method, r.URL.String(), time.Since(now))
 | |
| 	}(time.Now())
 | |
| 
 | |
| 	m.h.ServeHTTP(w, r)
 | |
| }
 | 
