aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2019-04-16 19:53:50 +0200
committerPřemysl Janouch <p@janouch.name>2019-04-16 19:53:50 +0200
commit0936963aaf8f9bbd367714c2dd7ce3a62ed6138c (patch)
treeb21850f28fe362c5aa07cc4e7a742f5eeab9f246
parente4ae5d00016a923363d4c21ae39a81506906ca4f (diff)
downloadsklad-0936963aaf8f9bbd367714c2dd7ce3a62ed6138c.tar.gz
sklad-0936963aaf8f9bbd367714c2dd7ce3a62ed6138c.tar.xz
sklad-0936963aaf8f9bbd367714c2dd7ce3a62ed6138c.zip
Avoid DB data races from different goroutines
-rw-r--r--cmd/sklad/main.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/cmd/sklad/main.go b/cmd/sklad/main.go
index c08ce2b..5f10348 100644
--- a/cmd/sklad/main.go
+++ b/cmd/sklad/main.go
@@ -12,6 +12,7 @@ import (
"path"
"path/filepath"
"strings"
+ "sync"
"time"
"janouch.name/sklad/imgutil"
@@ -308,6 +309,8 @@ func handleLabel(w http.ResponseWriter, r *http.Request) {
executeTemplate("label.tmpl", w, &params)
}
+var mutex sync.Mutex
+
func handle(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -317,6 +320,9 @@ func handle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
}
+ mutex.Lock()
+ defer mutex.Unlock()
+
switch _, base := path.Split(r.URL.Path); base {
case "login":
handleLogin(w, r)