Skip to content

Commit

Permalink
Adding lock to write it to map (#1531)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-gopalswami authored Jan 13, 2025
1 parent 3833744 commit cfdeeab
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion framework/components/fake/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit cfdeeab

Please sign in to comment.