add mutex lock

This commit is contained in:
Alexander Khodyrev 2024-09-14 11:22:09 +03:00
parent a4b764ad52
commit ae62fd9c2b

View file

@ -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"))