From 1807721360866ee71962b36376029d7ead296eed Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 2 Oct 2019 20:38:20 -0400 Subject: [PATCH] Add proper check for dst pointer --- memory.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/memory.go b/memory.go index 6f3001d..0814251 100644 --- a/memory.go +++ b/memory.go @@ -8,7 +8,8 @@ import ( ) var ( - MemoryCacheNotExists = errors.New("item does not exist") + ErrMemoryCacheNotExists = errors.New("item does not exist") + ErrMemoryCacheNotSupported = errors.New("memory cache does not support retrieving items without a destination pointer") ) type MemoryCache struct { @@ -31,7 +32,11 @@ func (mc *MemoryCache) Get(key string, dst ...interface{}) ([]byte, error) { item, exists := mc.c.Get(key) if !exists { - return nil, MemoryCacheNotExists + return nil, ErrMemoryCacheNotExists + } + + if len(dst) == 0 { + return nil, ErrMemoryCacheNotSupported } v := dst[0]