From c354bece5f9bb9274b923a0556a088f899bfb49c Mon Sep 17 00:00:00 2001 From: sbouaram Date: Fri, 19 May 2023 10:58:37 +0200 Subject: [PATCH] refactoring groupcache --- utils/storage/groupcache.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/utils/storage/groupcache.go b/utils/storage/groupcache.go index e45b00d..01f444e 100644 --- a/utils/storage/groupcache.go +++ b/utils/storage/groupcache.go @@ -38,10 +38,7 @@ func NewGroupCacheHandler(cfg *viper.Viper) (*GroupCacheHandler, error) { if resp == nil { return fmt.Errorf("key not found in etcd: %s", key) } - jsonResp, err := json.Marshal(resp.(map[string]interface{})) - if err != nil { - // Handle the error - } + jsonResp, _ := json.Marshal(resp) dest.SetBytes(jsonResp, time.Now().Add(time.Duration(cacheTTL)*time.Minute)) return nil @@ -152,18 +149,12 @@ func (h *GroupCacheHandler) Get(k string) (any, error) { return nil, err } - // If the value is empty, return an empty map - if len(value) == 0 { - return make(map[string]interface{}), nil - } - - var result map[string]interface{} + var result any err = json.Unmarshal(value, &result) if err != nil { return nil, err } return result, nil - } func (h *GroupCacheHandler) Delete(k string) error {