diff --git a/go.mod b/go.mod
index bd54f87..ec32a51 100644
--- a/go.mod
+++ b/go.mod
@@ -8,7 +8,7 @@ require (
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
github.com/emvi/api-go v0.0.0-20191210194347-0a945446f6a8
github.com/emvi/logbuch v1.1.1
- github.com/emvi/pirsch v0.0.0-20200623193552-b3a3d4a6434d
+ github.com/emvi/pirsch v0.0.0-20200624123353-86381b017755
github.com/gorilla/mux v1.7.4
github.com/gosimple/slug v1.9.0
github.com/jmoiron/sqlx v1.2.0 // indirect
diff --git a/go.sum b/go.sum
index c65b544..8a46cdd 100644
--- a/go.sum
+++ b/go.sum
@@ -87,6 +87,8 @@ github.com/emvi/pirsch v0.0.0-20200623192632-5c5fcd1d78cc h1:G05tiq3JKZwjnPSObRB
github.com/emvi/pirsch v0.0.0-20200623192632-5c5fcd1d78cc/go.mod h1:+YmBbltJ3feZz9L/QQyqwywltYvQKBfzrGD51TPKl5g=
github.com/emvi/pirsch v0.0.0-20200623193552-b3a3d4a6434d h1:+HRIYgA9AaXlGFQfhXpUShXxJ1knG2stwNIai1M6mzs=
github.com/emvi/pirsch v0.0.0-20200623193552-b3a3d4a6434d/go.mod h1:+YmBbltJ3feZz9L/QQyqwywltYvQKBfzrGD51TPKl5g=
+github.com/emvi/pirsch v0.0.0-20200624123353-86381b017755 h1:TdiDC7+IfV6giMtFNvbYKFlSPJJZewr9jfh3KGcr8QQ=
+github.com/emvi/pirsch v0.0.0-20200624123353-86381b017755/go.mod h1:+YmBbltJ3feZz9L/QQyqwywltYvQKBfzrGD51TPKl5g=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE=
diff --git a/main.go b/main.go
index 01b098f..075584d 100644
--- a/main.go
+++ b/main.go
@@ -1,10 +1,9 @@
package main
import (
- "database/sql"
- "fmt"
"github.com/Kugelschieber/marvinblum.de/blog"
"github.com/Kugelschieber/marvinblum.de/tpl"
+ "github.com/Kugelschieber/marvinblum.de/tracking"
"github.com/NYTimes/gziphandler"
"github.com/caddyserver/certmagic"
emvi "github.com/emvi/api-go"
@@ -16,17 +15,15 @@ import (
"html/template"
"net/http"
"os"
- "strconv"
"strings"
"time"
)
const (
- staticDir = "static"
- staticDirPrefix = "/static/"
- logTimeFormat = "2006-01-02_15:04:05"
- envPrefix = "MB_"
- connectionString = `host=%s port=%s user=%s password=%s dbname=%s sslmode=%s sslcert=%s sslkey=%s sslrootcert=%s connectTimeout=%s timezone=%s`
+ staticDir = "static"
+ staticDirPrefix = "/static/"
+ logTimeFormat = "2006-01-02_15:04:05"
+ envPrefix = "MB_"
)
var (
@@ -58,53 +55,6 @@ func logEnvConfig() {
}
}
-func setupTracker() {
- logbuch.Info("Connecting to database...")
- host := os.Getenv("MB_DB_HOST")
- port := os.Getenv("MB_DB_PORT")
- user := os.Getenv("MB_DB_USER")
- password := os.Getenv("MB_DB_PASSWORD")
- schema := os.Getenv("MB_DB_SCHEMA")
- sslMode := os.Getenv("MB_DB_SSLMODE")
- sslCert := os.Getenv("MB_DB_SSLCERT")
- sslKey := os.Getenv("MB_DB_SSLKEY")
- sslRootCert := os.Getenv("MB_DB_SSLROOTCERT")
- zone, offset := time.Now().Zone()
- timezone := zone + strconv.Itoa(-offset/3600)
- logbuch.Info("Setting time zone", logbuch.Fields{"timezone": timezone})
- connectionStr := fmt.Sprintf(connectionString, host, port, user, password, schema, sslMode, sslCert, sslKey, sslRootCert, "30", timezone)
- db, err := sql.Open("postgres", connectionStr)
-
- if err != nil {
- logbuch.Fatal("Error connecting to database", logbuch.Fields{"err": err})
- }
-
- if err := db.Ping(); err != nil {
- logbuch.Fatal("Error pinging database", logbuch.Fields{"err": err})
- }
-
- store := pirsch.NewPostgresStore(db)
- tracker = pirsch.NewTracker(store, nil)
- processor := pirsch.NewProcessor(store)
- processTrackingData(processor)
- pirsch.RunAtMidnight(func() {
- processTrackingData(processor)
- })
-}
-
-func processTrackingData(processor *pirsch.Processor) {
- logbuch.Info("Processing tracking data...")
-
- defer func() {
- if err := recover(); err != nil {
- logbuch.Error("Error processing tracking data", logbuch.Fields{"err": err})
- }
- }()
-
- processor.Process()
- logbuch.Info("Done processing tracking data")
-}
-
func serveAbout() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
tracker.Hit(r)
@@ -217,7 +167,7 @@ func start(handler http.Handler) {
func main() {
configureLog()
logEnvConfig()
- setupTracker()
+ tracker = tracking.NewTracker()
tplCache = tpl.NewCache()
blogInstance = blog.NewBlog(tplCache)
router := setupRouter()
diff --git a/template/about.html b/template/about.html
index 42cce9e..d28c66b 100644
--- a/template/about.html
+++ b/template/about.html
@@ -11,14 +11,14 @@
{{template "menu.html"}}
I'm a full stack software engineer from Germany, open source and Linux enthusiast and co-founder of Emvi.
In love with Go, but fluent in a lot of programming languages.
{{$article.LatestArticleContent.Title}}
@@ -32,11 +32,14 @@
who am I?
+ Who Am I?
latest blog posts
+ Latest Blog Posts
{{range $article := .Articles}}
projects
+ Projects
skills
+ Skills
work
+ Work
Blog
- {{range $year, $articles := .Articles}}
+{{$year}}
{{range $article := $articles}}
@@ -12,9 +14,11 @@
{{format $article.Published "2. January 2006"}}
There are no blog posts yet...
- {{end}} -- Like to see more? Read my blog articles on Emvi, my project page on GitHub or send me a mail. + Would you like to see more? Read my blog articles on Emvi, my project page on GitHub or send me a mail.
This page uses concrete for styling. Check it out!