chirpy_server/metrics.go
2024-10-14 23:00:46 +02:00

19 lines
404 B
Go

package main
import (
"fmt"
"net/http"
)
func (cfg *apiConfig) middlewareMetricsInc(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
cfg.fileserverHits.Add(1)
next.ServeHTTP(w, req)
})
}
func (cfg *apiConfig) serveMetrics(w http.ResponseWriter, r *http.Request) {
hits := cfg.fileserverHits.Load()
fmt.Fprintf(w, "Hits: %d", hits)
}