Avoid DB data races from different goroutines
This commit is contained in:
parent
e4ae5d0001
commit
0936963aaf
|
@ -12,6 +12,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"janouch.name/sklad/imgutil"
|
"janouch.name/sklad/imgutil"
|
||||||
|
@ -308,6 +309,8 @@ func handleLabel(w http.ResponseWriter, r *http.Request) {
|
||||||
executeTemplate("label.tmpl", w, ¶ms)
|
executeTemplate("label.tmpl", w, ¶ms)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mutex sync.Mutex
|
||||||
|
|
||||||
func handle(w http.ResponseWriter, r *http.Request) {
|
func handle(w http.ResponseWriter, r *http.Request) {
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
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")
|
w.Header().Set("Cache-Control", "no-store")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
|
|
||||||
switch _, base := path.Split(r.URL.Path); base {
|
switch _, base := path.Split(r.URL.Path); base {
|
||||||
case "login":
|
case "login":
|
||||||
handleLogin(w, r)
|
handleLogin(w, r)
|
||||||
|
|
Loading…
Reference in New Issue