Skip to content

Commit cfdeeab

Browse files
authored
Adding lock to write it to map (#1531)
1 parent 3833744 commit cfdeeab

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

framework/components/fake/record.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
"github.com/gin-gonic/gin"
77
"io/ioutil"
88
"net/http"
9+
"sync"
910
)
1011

1112
var (
12-
R = NewRecords()
13+
R = NewRecords()
14+
mu sync.Mutex
1315
)
1416

1517
// Record is a request and response data
@@ -78,6 +80,8 @@ func recordMiddleware() gin.HandlerFunc {
7880
// Capture response data
7981
resBody := customWriter.body.String()
8082
status := c.Writer.Status()
83+
mu.Lock()
84+
defer mu.Unlock()
8185
if R.Data[c.Request.URL.Path] == nil {
8286
R.Data[c.Request.URL.Path] = make([]*Record, 0)
8387
}

0 commit comments

Comments
 (0)