Spawn go routines for hits.

This commit is contained in:
Marvin Blum
2020-09-30 14:31:04 +02:00
committed by GitHub
parent 2057121e33
commit e42ea6f2a1

10
main.go
View File

@@ -38,7 +38,7 @@ var (
func serveAbout() http.HandlerFunc { func serveAbout() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
tracker.Hit(r, nil) go tracker.Hit(r, nil)
tplCache.Render(w, "about.html", struct { tplCache.Render(w, "about.html", struct {
Articles []emvi.Article Articles []emvi.Article
}{ }{
@@ -49,14 +49,14 @@ func serveAbout() http.HandlerFunc {
func serveLegal() http.HandlerFunc { func serveLegal() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
tracker.Hit(r, nil) go tracker.Hit(r, nil)
tplCache.Render(w, "legal.html", nil) tplCache.Render(w, "legal.html", nil)
} }
} }
func serveBlogPage() http.HandlerFunc { func serveBlogPage() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
tracker.Hit(r, nil) go tracker.Hit(r, nil)
tplCache.Render(w, "blog.html", struct { tplCache.Render(w, "blog.html", struct {
Articles map[int][]emvi.Article Articles map[int][]emvi.Article
}{ }{
@@ -83,7 +83,7 @@ func serveBlogArticle() http.HandlerFunc {
} }
// track the hit if the article was found, otherwise we don't care // track the hit if the article was found, otherwise we don't care
tracker.Hit(r, nil) go tracker.Hit(r, nil)
tplCache.RenderWithoutCache(w, "article.html", struct { tplCache.RenderWithoutCache(w, "article.html", struct {
Title string Title string
@@ -99,7 +99,7 @@ func serveBlogArticle() http.HandlerFunc {
func serveTracking() http.HandlerFunc { func serveTracking() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
tracker.Hit(r, nil) go tracker.Hit(r, nil)
start, _ := strconv.Atoi(r.URL.Query().Get("start")) start, _ := strconv.Atoi(r.URL.Query().Get("start"))
if start > 365 { if start > 365 {