From b680aaae68ec431913ded5e13f81c7929acc6615 Mon Sep 17 00:00:00 2001 From: Pieter Joost van de Sande Date: Mon, 15 Jul 2013 19:29:56 +0200 Subject: [PATCH] Return map instead of pointer value As kisielk just [told me](https://github.com/pjvds/context/commit/709e005f84167f4206737b8ba6c560d1ebb18b85#commitcomment-3636470), maps can be nil --- context.go | 4 ++-- context_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index f6f0117..e5374db 100644 --- a/context.go +++ b/context.go @@ -49,12 +49,12 @@ func GetOk(r *http.Request, key interface{}) (interface{}, bool) { } // GetAll returns all stored values for the request as a map. Nil is returned for invalid requests. -func GetAll(r *http.Request) *map[interface{}]interface{} { +func GetAll(r *http.Request) map[interface{}]interface{} { mutex.Lock() defer mutex.Unlock() if context, ok := data[r]; ok { - return &context + return context } return nil } diff --git a/context_test.go b/context_test.go index 0742c81..68f25e9 100644 --- a/context_test.go +++ b/context_test.go @@ -54,7 +54,7 @@ func TestContext(t *testing.T) { // GetAll() values := GetAll(r) - assertEqual(len(*values), 3) + assertEqual(len(values), 3) // GetAll() for empty request values = GetAll(emptyR)