From b3f0d63b4dace09a1dd65b53db1f7463a3eb5c56 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Wed, 11 Oct 2023 20:52:13 +0200 Subject: [PATCH] fix bug --- reflector/protected_content.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/reflector/protected_content.go b/reflector/protected_content.go index 49f1dc3..377cabd 100644 --- a/reflector/protected_content.go +++ b/reflector/protected_content.go @@ -19,7 +19,7 @@ type ProtectedContent struct { var protectedCache = gcache.New(10).Expiration(2 * time.Minute).Build() -func GetProtectedContent() (map[string]bool, error) { +func GetProtectedContent() (interface{}, error) { cachedVal, err := protectedCache.Get("protected") if err == nil && cachedVal != nil { return cachedVal.(map[string]bool), nil @@ -68,15 +68,14 @@ func GetProtectedContent() (map[string]bool, error) { var sf = singleflight.Group{} func IsProtected(sdHash string) bool { - val, err, _ := sf.Do("protected", func() (interface{}, error) { - protectedMap, err := GetProtectedContent() - if err != nil { - return nil, err - } - return protectedMap[sdHash], nil - }) + val, err, _ := sf.Do("protected", GetProtectedContent) if err != nil { return false } - return val.(bool) + cachedMap, ok := val.(map[string]bool) + if !ok { + return false + } + + return cachedMap[sdHash] }