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) { w.Header().Add("Content-Type", "text/html") hits := cfg.fileserverHits.Load() template := `
Chirpy has been visited %d times!
` fmt.Fprintf(w, template, hits) }