mirror of
https://github.com/Kugelschieber/marvinblum.git
synced 2026-01-18 14:50:27 +00:00
Small refactoring and improved legal page and more whitespace.
This commit is contained in:
2
go.mod
2
go.mod
@@ -8,7 +8,7 @@ require (
|
|||||||
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
|
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
|
||||||
github.com/emvi/api-go v0.0.0-20191210194347-0a945446f6a8
|
github.com/emvi/api-go v0.0.0-20191210194347-0a945446f6a8
|
||||||
github.com/emvi/logbuch v1.1.1
|
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/gorilla/mux v1.7.4
|
||||||
github.com/gosimple/slug v1.9.0
|
github.com/gosimple/slug v1.9.0
|
||||||
github.com/jmoiron/sqlx v1.2.0 // indirect
|
github.com/jmoiron/sqlx v1.2.0 // indirect
|
||||||
|
|||||||
2
go.sum
2
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-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 h1:+HRIYgA9AaXlGFQfhXpUShXxJ1knG2stwNIai1M6mzs=
|
||||||
github.com/emvi/pirsch v0.0.0-20200623193552-b3a3d4a6434d/go.mod h1:+YmBbltJ3feZz9L/QQyqwywltYvQKBfzrGD51TPKl5g=
|
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/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/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=
|
github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE=
|
||||||
|
|||||||
54
main.go
54
main.go
@@ -1,10 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"github.com/Kugelschieber/marvinblum.de/blog"
|
"github.com/Kugelschieber/marvinblum.de/blog"
|
||||||
"github.com/Kugelschieber/marvinblum.de/tpl"
|
"github.com/Kugelschieber/marvinblum.de/tpl"
|
||||||
|
"github.com/Kugelschieber/marvinblum.de/tracking"
|
||||||
"github.com/NYTimes/gziphandler"
|
"github.com/NYTimes/gziphandler"
|
||||||
"github.com/caddyserver/certmagic"
|
"github.com/caddyserver/certmagic"
|
||||||
emvi "github.com/emvi/api-go"
|
emvi "github.com/emvi/api-go"
|
||||||
@@ -16,7 +15,6 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -26,7 +24,6 @@ const (
|
|||||||
staticDirPrefix = "/static/"
|
staticDirPrefix = "/static/"
|
||||||
logTimeFormat = "2006-01-02_15:04:05"
|
logTimeFormat = "2006-01-02_15:04:05"
|
||||||
envPrefix = "MB_"
|
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`
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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 {
|
func serveAbout() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tracker.Hit(r)
|
tracker.Hit(r)
|
||||||
@@ -217,7 +167,7 @@ func start(handler http.Handler) {
|
|||||||
func main() {
|
func main() {
|
||||||
configureLog()
|
configureLog()
|
||||||
logEnvConfig()
|
logEnvConfig()
|
||||||
setupTracker()
|
tracker = tracking.NewTracker()
|
||||||
tplCache = tpl.NewCache()
|
tplCache = tpl.NewCache()
|
||||||
blogInstance = blog.NewBlog(tplCache)
|
blogInstance = blog.NewBlog(tplCache)
|
||||||
router := setupRouter()
|
router := setupRouter()
|
||||||
|
|||||||
@@ -11,14 +11,14 @@
|
|||||||
{{template "menu.html"}}
|
{{template "menu.html"}}
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h2>who am I?</h2>
|
<h2>Who Am I?</h2>
|
||||||
<p>
|
<p>
|
||||||
I'm a full stack software engineer from Germany, open source and Linux enthusiast and co-founder of <a href="https://emvi.com/" target="_blank">Emvi</a>.
|
I'm a full stack software engineer from Germany, open source and Linux enthusiast and co-founder of <a href="https://emvi.com/" target="_blank">Emvi</a>.
|
||||||
In love with Go, but fluent in a lot of programming languages.
|
In love with Go, but fluent in a lot of programming languages.
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>latest blog posts</h2>
|
<h2>Latest Blog Posts</h2>
|
||||||
{{range $article := .Articles}}
|
{{range $article := .Articles}}
|
||||||
<p>
|
<p>
|
||||||
<a href="/blog/{{slug $article.LatestArticleContent.Title}}-{{$article.Id}}">{{$article.LatestArticleContent.Title}}</a>
|
<a href="/blog/{{slug $article.LatestArticleContent.Title}}-{{$article.Id}}">{{$article.LatestArticleContent.Title}}</a>
|
||||||
@@ -32,11 +32,14 @@
|
|||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>projects</h2>
|
<h2>Projects</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a href="https://emvi.com/" target="_blank">Emvi</a> a note taking, collaboration and knowledge management tool for personal use and teams of any size
|
<a href="https://emvi.com/" target="_blank">Emvi</a> a note taking, collaboration and knowledge management tool for personal use and teams of any size
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://github.com/emvi/pirsch" target="_blank">pirsch</a> a server side, no-cookie and privacy focused tracking library for Golang
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="https://github.com/emvi/logbuch" target="_blank">logbuch</a> a simple Golang logging library
|
<a href="https://github.com/emvi/logbuch" target="_blank">logbuch</a> a simple Golang logging library
|
||||||
</li>
|
</li>
|
||||||
@@ -52,7 +55,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>skills</h2>
|
<h2>Skills</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Go (Golang)</li>
|
<li>Go (Golang)</li>
|
||||||
<li>JavaScript (Vue, Node)</li>
|
<li>JavaScript (Vue, Node)</li>
|
||||||
@@ -66,7 +69,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>work</h2>
|
<h2>Work</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a href="https://emvi.com/" target="_blank">Emvi</a> co-founder of a note taking, collaboration and knowledge management SaaS startup
|
<a href="https://emvi.com/" target="_blank">Emvi</a> co-founder of a note taking, collaboration and knowledge management SaaS startup
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h1>Blog</h1>
|
<h1>Blog</h1>
|
||||||
|
</section>
|
||||||
{{range $year, $articles := .Articles}}
|
{{range $year, $articles := .Articles}}
|
||||||
|
<section>
|
||||||
<h2>{{$year}}</h2>
|
<h2>{{$year}}</h2>
|
||||||
|
|
||||||
{{range $article := $articles}}
|
{{range $article := $articles}}
|
||||||
@@ -12,9 +14,11 @@
|
|||||||
<small>{{format $article.Published "2. January 2006"}}</small>
|
<small>{{format $article.Published "2. January 2006"}}</small>
|
||||||
</p>
|
</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else}}
|
|
||||||
<p>There are no blog posts yet...</p>
|
|
||||||
{{end}}
|
|
||||||
</section>
|
</section>
|
||||||
|
{{else}}
|
||||||
|
<section>
|
||||||
|
<p>There are no blog posts yet...</p>
|
||||||
|
</section>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{template "end.html"}}
|
{{template "end.html"}}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<hr />
|
<hr />
|
||||||
<section>
|
<section>
|
||||||
<p>
|
<p>
|
||||||
Like to see more? Read my blog articles on <a href="https://emvi.com/blog" target="_blank">Emvi</a>, my project page on <a href="https://github.com/Kugelschieber" target="_blank">GitHub</a> or send me a <a href="mailto:marvin@marvinblum.de">mail</a>.
|
Would you like to see more? Read my blog articles on <a href="https://emvi.com/blog" target="_blank">Emvi</a>, my project page on <a href="https://github.com/Kugelschieber" target="_blank">GitHub</a> or send me a <a href="mailto:marvin@marvinblum.de">mail</a>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
This page uses <a href="https://concrete.style/" target="_blank">concrete</a> for styling. Check it out!
|
This page uses <a href="https://concrete.style/" target="_blank">concrete</a> for styling. Check it out!
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a href="/legal">Legal</a>
|
This page does not use Cookies. <a href="/legal">Legal</a>
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
{{template "head.html"}}
|
{{template "head.html"}}
|
||||||
{{template "menu.html"}}
|
{{template "menu.html"}}
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h1>Legal</h1>
|
||||||
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>According to §5 TMG</h2>
|
<h2>According to §5 TMG</h2>
|
||||||
<p>
|
<p>
|
||||||
@@ -10,5 +13,11 @@
|
|||||||
<a href="mailto:marvin@marvinblum.de">marvin@marvinblum.de</a>
|
<a href="mailto:marvin@marvinblum.de">marvin@marvinblum.de</a>
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
<section>
|
||||||
|
<h2>Cookie Policy</h2>
|
||||||
|
<p>
|
||||||
|
This page does not use cookies.
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
{{template "end.html"}}
|
{{template "end.html"}}
|
||||||
|
|||||||
66
tracking/tracking.go
Normal file
66
tracking/tracking.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package tracking
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"github.com/emvi/logbuch"
|
||||||
|
"github.com/emvi/pirsch"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
connectionString = `host=%s port=%s user=%s password=%s dbname=%s sslmode=%s sslcert=%s sslkey=%s sslrootcert=%s connectTimeout=%s timezone=%s`
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewTracker() *pirsch.Tracker {
|
||||||
|
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})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.Ping(); err != nil {
|
||||||
|
logbuch.Fatal("Error pinging database", logbuch.Fields{"err": err})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
store := pirsch.NewPostgresStore(db)
|
||||||
|
tracker := pirsch.NewTracker(store, nil)
|
||||||
|
processor := pirsch.NewProcessor(store)
|
||||||
|
processTrackingData(processor)
|
||||||
|
pirsch.RunAtMidnight(func() {
|
||||||
|
processTrackingData(processor)
|
||||||
|
})
|
||||||
|
|
||||||
|
return tracker
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user