refactoring groupcache

This commit is contained in:
sbouaram 2023-05-19 10:58:37 +02:00
parent 6299a6c7be
commit c354bece5f
1 changed files with 2 additions and 11 deletions

View File

@ -38,10 +38,7 @@ func NewGroupCacheHandler(cfg *viper.Viper) (*GroupCacheHandler, error) {
if resp == nil { if resp == nil {
return fmt.Errorf("key not found in etcd: %s", key) return fmt.Errorf("key not found in etcd: %s", key)
} }
jsonResp, err := json.Marshal(resp.(map[string]interface{})) jsonResp, _ := json.Marshal(resp)
if err != nil {
// Handle the error
}
dest.SetBytes(jsonResp, time.Now().Add(time.Duration(cacheTTL)*time.Minute)) dest.SetBytes(jsonResp, time.Now().Add(time.Duration(cacheTTL)*time.Minute))
return nil return nil
@ -152,18 +149,12 @@ func (h *GroupCacheHandler) Get(k string) (any, error) {
return nil, err return nil, err
} }
// If the value is empty, return an empty map var result any
if len(value) == 0 {
return make(map[string]interface{}), nil
}
var result map[string]interface{}
err = json.Unmarshal(value, &result) err = json.Unmarshal(value, &result)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return result, nil return result, nil
} }
func (h *GroupCacheHandler) Delete(k string) error { func (h *GroupCacheHandler) Delete(k string) error {