From ae62fd9c2b5b5e79264d26b3317eef948b6119ac Mon Sep 17 00:00:00 2001 From: Alexander Khodyrev Date: Sat, 14 Sep 2024 11:22:09 +0300 Subject: [PATCH] add mutex lock --- birdtown-visit-counter.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/birdtown-visit-counter.go b/birdtown-visit-counter.go index 6bf4f1e..064241e 100644 --- a/birdtown-visit-counter.go +++ b/birdtown-visit-counter.go @@ -55,7 +55,9 @@ func (h *visitsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } if r.Method == http.MethodGet { + h.store.Lock() jsonBytes, err := json.Marshal(h.store.m) + h.store.Unlock() if err != nil { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("cannot serialize"))