File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 55 "net"
66 "net/http"
77 "strings"
8+ "sync"
89
910 "golang.org/x/net/context"
1011 "golang.org/x/net/websocket"
@@ -60,6 +61,7 @@ type Ctx struct {
6061 formParsed bool
6162 multipartFormParsed bool
6263 parent Context
64+ m * sync.RWMutex
6365}
6466
6567var _ context.Context = & Ctx {}
@@ -178,17 +180,26 @@ func (c *Ctx) ParseMultipartForm(maxMemory int64) error {
178180// Set is used to store a new key/value pair exclusivelly for thisContext.
179181// It also lazy initializes c.Keys if it was not used previously.
180182func (c * Ctx ) Set (key string , value interface {}) {
183+
181184 if c .store == nil {
185+ c .m = new (sync.RWMutex )
186+ c .m .Lock ()
182187 c .store = make (store )
188+ } else {
189+ c .m .Lock ()
183190 }
191+
184192 c .store [key ] = value
193+ c .m .Unlock ()
185194}
186195
187196// Get returns the value for the given key, ie: (value, true).
188197// If the value does not exists it returns (nil, false)
189198func (c * Ctx ) Get (key string ) (value interface {}, exists bool ) {
190199 if c .store != nil {
200+ c .m .RLock ()
191201 value , exists = c .store [key ]
202+ c .m .RUnlock ()
192203 }
193204 return
194205}
Original file line number Diff line number Diff line change 55 "net/http"
66 "net/http/httptest"
77 "os"
8+ "sync"
89 "testing"
910
1011 . "gopkg.in/go-playground/assert.v1"
@@ -107,6 +108,7 @@ func TestContext(t *testing.T) {
107108 }
108109
109110 c .params = varParams
111+ c .m = new (sync.RWMutex )
110112 c .store = storeMap
111113 c .request = r
112114
You can’t perform that action at this time.
0 commit comments