From 5eca3843cceeef1ce667a16c6af6f86139178cd3 Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Tue, 6 Jun 2017 14:31:32 +0000 Subject: [PATCH] Let's instrument the response time before writting the template --- lib/stats.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/stats.go b/lib/stats.go index f473377..f4ccd96 100644 --- a/lib/stats.go +++ b/lib/stats.go @@ -26,10 +26,13 @@ type handler struct { template *Template hostname string ro bool + t1 time.Time } func (h handler) load(tmpl string, data interface{}) { var err error + + h.t1 = time.Now() fmt := h.r.FormValue("fmt") switch fmt { case "rss": @@ -91,8 +94,10 @@ func (sg StatsGatherer) Gather(function func(handler)) func(http.ResponseWriter, t0 := time.Now() function(h) - t1 := time.Now() - sg.channel <- statsRequest{r, t1.Sub(t0)} + if h.t1.IsZero() { + h.t1 = time.Now() + } + sg.channel <- statsRequest{r, h.t1.Sub(t0)} } }