Added automatic database migration.

This commit is contained in:
Marvin Blum
2020-09-10 22:13:07 +02:00
committed by Marvin Blum
parent 5b800991c8
commit 47e6ecfadd
7 changed files with 804 additions and 42 deletions

48
main.go
View File

@@ -3,6 +3,7 @@ package main
import (
"context"
"github.com/Kugelschieber/marvinblum.de/blog"
"github.com/Kugelschieber/marvinblum.de/db"
"github.com/Kugelschieber/marvinblum.de/tpl"
"github.com/Kugelschieber/marvinblum.de/tracking"
"github.com/NYTimes/gziphandler"
@@ -35,29 +36,6 @@ var (
blogInstance *blog.Blog
)
func configureLog() {
logbuch.SetFormatter(logbuch.NewFieldFormatter(logTimeFormat, "\t\t"))
logbuch.Info("Configure logging...")
level := strings.ToLower(os.Getenv("MB_LOGLEVEL"))
if level == "debug" {
logbuch.SetLevel(logbuch.LevelDebug)
} else if level == "info" {
logbuch.SetLevel(logbuch.LevelInfo)
} else {
logbuch.SetLevel(logbuch.LevelWarning)
}
}
func logEnvConfig() {
for _, e := range os.Environ() {
if strings.HasPrefix(e, envPrefix) {
pair := strings.Split(e, "=")
logbuch.Info(pair[0] + "=" + pair[1])
}
}
}
func serveAbout() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
tracker.Hit(r, nil)
@@ -207,6 +185,29 @@ func setupRouter() *mux.Router {
return router
}
func configureLog() {
logbuch.SetFormatter(logbuch.NewFieldFormatter(logTimeFormat, "\t\t"))
logbuch.Info("Configure logging...")
level := strings.ToLower(os.Getenv("MB_LOGLEVEL"))
if level == "debug" {
logbuch.SetLevel(logbuch.LevelDebug)
} else if level == "info" {
logbuch.SetLevel(logbuch.LevelInfo)
} else {
logbuch.SetLevel(logbuch.LevelWarning)
}
}
func logEnvConfig() {
for _, e := range os.Environ() {
if strings.HasPrefix(e, envPrefix) {
pair := strings.Split(e, "=")
logbuch.Info(pair[0] + "=" + pair[1])
}
}
}
func configureCors(router *mux.Router) http.Handler {
logbuch.Info("Configuring CORS...")
@@ -251,6 +252,7 @@ func start(handler http.Handler, trackingCancel context.CancelFunc) {
func main() {
configureLog()
logEnvConfig()
db.Migrate()
var trackingCancel context.CancelFunc
tracker, trackingCancel = tracking.NewTracker()
tplCache = tpl.NewCache()