Update gorilla/context

Race condition was fixed recently
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
This commit is contained in:
LK4D4 2014-06-28 12:38:29 +04:00
parent 4a9dc8d73d
commit ea464ea212
2 changed files with 16 additions and 7 deletions

View file

@ -41,7 +41,7 @@ clone() {
clone git github.com/kr/pty 67e2db24c8
clone git github.com/gorilla/context b06ed15e1c
clone git github.com/gorilla/context 14f550f51a
clone git github.com/gorilla/mux 136d54f81f

View file

@ -30,9 +30,10 @@ func Set(r *http.Request, key, val interface{}) {
// Get returns a value stored for a given key in a given request.
func Get(r *http.Request, key interface{}) interface{} {
mutex.RLock()
if data[r] != nil {
if ctx := data[r]; ctx != nil {
value := ctx[key]
mutex.RUnlock()
return data[r][key]
return value
}
mutex.RUnlock()
return nil
@ -54,20 +55,28 @@ func GetOk(r *http.Request, key interface{}) (interface{}, bool) {
func GetAll(r *http.Request) map[interface{}]interface{} {
mutex.RLock()
if context, ok := data[r]; ok {
result := make(map[interface{}]interface{}, len(context))
for k, v := range context {
result[k] = v
}
mutex.RUnlock()
return context
return result
}
mutex.RUnlock()
return nil
}
// GetAllOk returns all stored values for the request as a map. It returns not
// ok if the request was never registered.
// GetAllOk returns all stored values for the request as a map and a boolean value that indicates if
// the request was registered.
func GetAllOk(r *http.Request) (map[interface{}]interface{}, bool) {
mutex.RLock()
context, ok := data[r]
result := make(map[interface{}]interface{}, len(context))
for k, v := range context {
result[k] = v
}
mutex.RUnlock()
return context, ok
return result, ok
}
// Delete removes a value stored for a given key in a given request.