CaIon 5 месяцев назад
Родитель
Сommit
e3d3e697d3
1 измененных файлов с 5 добавлено и 0 удалено
  1. 5 0
      common/custom-event.go

+ 5 - 0
common/custom-event.go

@@ -9,6 +9,7 @@ import (
 	"io"
 	"net/http"
 	"strings"
+	"sync"
 )
 
 type stringWriter interface {
@@ -52,6 +53,8 @@ type CustomEvent struct {
 	Id    string
 	Retry uint
 	Data  interface{}
+
+	Mutex sync.Mutex
 }
 
 func encode(writer io.Writer, event CustomEvent) error {
@@ -73,6 +76,8 @@ func (r CustomEvent) Render(w http.ResponseWriter) error {
 }
 
 func (r CustomEvent) WriteContentType(w http.ResponseWriter) {
+	r.Mutex.Lock()
+	defer r.Mutex.Unlock()
 	header := w.Header()
 	header["Content-Type"] = contentType