diff options
Diffstat (limited to 'vendor/src/github.com/gorilla/context/context.go')
-rw-r--r-- | vendor/src/github.com/gorilla/context/context.go | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/vendor/src/github.com/gorilla/context/context.go b/vendor/src/github.com/gorilla/context/context.go index a7f7d85bb4..81cb128b19 100644 --- a/vendor/src/github.com/gorilla/context/context.go +++ b/vendor/src/github.com/gorilla/context/context.go @@ -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. |