From cfdeeabd0f39d166bc433820dcb745542126fbba Mon Sep 17 00:00:00 2001 From: Balamurali Gopalswami <167726375+b-gopalswami@users.noreply.github.com> Date: Mon, 13 Jan 2025 12:19:17 -0500 Subject: [PATCH] Adding lock to write it to map (#1531) --- framework/components/fake/record.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/components/fake/record.go b/framework/components/fake/record.go index 9387d3cd0..7cc771cba 100644 --- a/framework/components/fake/record.go +++ b/framework/components/fake/record.go @@ -6,10 +6,12 @@ import ( "github.com/gin-gonic/gin" "io/ioutil" "net/http" + "sync" ) var ( - R = NewRecords() + R = NewRecords() + mu sync.Mutex ) // Record is a request and response data @@ -78,6 +80,8 @@ func recordMiddleware() gin.HandlerFunc { // Capture response data resBody := customWriter.body.String() status := c.Writer.Status() + mu.Lock() + defer mu.Unlock() if R.Data[c.Request.URL.Path] == nil { R.Data[c.Request.URL.Path] = make([]*Record, 0) }