Total visitor and page visits statistics page.

This commit is contained in:
Marvin Blum
2020-06-24 17:47:36 +02:00
committed by Marvin Blum
parent e5eee70815
commit f93b85e6f4
8 changed files with 240 additions and 5 deletions

27
main.go
View File

@@ -16,6 +16,7 @@ import (
"net/http"
"os"
"os/signal"
"strconv"
"strings"
"time"
)
@@ -116,6 +117,31 @@ func serveBlogArticle() http.HandlerFunc {
}
}
func serveTracking() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
start, _ := strconv.Atoi(r.URL.Query().Get("start"))
if start > 365 {
start = 365
} else if start < 7 {
start = 7
}
totalVisitorsLabels, totalVisitorsDps := tracking.GetTotalVisitors(start)
tplCache.RenderWithoutCache(w, "tracking.html", struct {
Start int
TotalVisitorsLabels template.JS
TotalVisitorsDps template.JS
PageVisits []tracking.PageVisits
}{
start,
totalVisitorsLabels,
totalVisitorsDps,
tracking.GetPageVisits(start),
})
}
}
func serveNotFound() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
tplCache.Render(w, "notfound.html", nil)
@@ -128,6 +154,7 @@ func setupRouter() *mux.Router {
router.Handle("/blog/{slug}", serveBlogArticle())
router.Handle("/blog", serveBlogPage())
router.Handle("/legal", serveLegal())
router.Handle("/tracking", serveTracking())
router.Handle("/", serveAbout())
router.NotFoundHandler = serveNotFound()
return router