From 00e084bf1709b4f18475b32df45271993373d2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=90?= Date: Sat, 9 Mar 2024 09:44:10 +0800 Subject: [PATCH] feat: fix LoadPolicy() for Amazon MemoryDB for Redis (#45) --- adapter.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/adapter.go b/adapter.go index 56a198a..6266c07 100644 --- a/adapter.go +++ b/adapter.go @@ -303,7 +303,12 @@ func (a *Adapter) LoadPolicy(model model.Model) error { for _, value := range values { text, ok := value.([]byte) if !ok { - return errors.New("the type is wrong") + // Amazon MemoryDB for Redis returns string instead of []byte + if textStr, ok := value.(string); ok { + text = []byte(textStr) + } else { + return errors.New("the type is wrong") + } } err = json.Unmarshal(text, &line) if err != nil { @@ -545,7 +550,12 @@ func (a *Adapter) loadFilteredPolicy(model model.Model, filter *Filter) error { for _, value := range values { text, ok := value.([]byte) if !ok { - return errors.New("the type is wrong") + // Amazon MemoryDB for Redis returns string instead of []byte + if textStr, ok := value.(string); ok { + text = []byte(textStr) + } else { + return errors.New("the type is wrong") + } } if !re.Match(text) {