package handler import ( "fmt" "net/http" ) func (cfg *APIConfig) MiddlewareMetricsInc(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { cfg.FileserverHits.Add(1) next.ServeHTTP(w, r) }) } func (cfg *APIConfig) Metrics(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "text/html") w.WriteHeader(http.StatusOK) hits := cfg.FileserverHits.Load() template := `

Welcome, Chirpy Admin

Chirpy has been visited %d times!

` w.Write([]byte(fmt.Sprintf(template, hits))) }