From 94e981d7c773c21b52afdd1dbf6578f71e603781 Mon Sep 17 00:00:00 2001 From: xlanor Date: Fri, 2 Oct 2020 01:44:23 +0800 Subject: [PATCH] Changed policiesList and rolesList from declaration to definition to fix nil error in encoding/json. https://github.com/golang/go/issues/27589#issuecomment-545976192 --- engine/ladon/handler.go | 5 ++--- storage/handler.go | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/engine/ladon/handler.go b/engine/ladon/handler.go index e3e7b3e02..32341d5c2 100644 --- a/engine/ladon/handler.go +++ b/engine/ladon/handler.go @@ -290,8 +290,7 @@ func (e *Engine) Register(r *httprouter.Router) { } func (e *Engine) rolesList(ctx context.Context, r *http.Request, ps httprouter.Params) (*kstorage.ListRequest, error) { - var p kstorage.Roles - + p := make([]kstorage.Role, 0) f, err := flavor(ps) if err != nil { return nil, err @@ -428,8 +427,8 @@ func (e *Engine) policiesCreate(ctx context.Context, r *http.Request, ps httprou } func (e *Engine) policiesList(ctx context.Context, r *http.Request, ps httprouter.Params) (*kstorage.ListRequest, error) { - var p kstorage.Policies + p := make([]kstorage.Policy, 0) f, err := flavor(ps) if err != nil { return nil, err diff --git a/storage/handler.go b/storage/handler.go index 9949e1dee..e4ed8efee 100644 --- a/storage/handler.go +++ b/storage/handler.go @@ -84,8 +84,8 @@ func (l *ListRequest) Filter(m map[string][]string) *ListRequest { func ListByQuery(l *ListRequest, m map[string][]string) { switch val := l.Value.(type) { - case *Roles: - var res Roles + case *[]Role: + res := make([]Role, 0) for _, role := range *val { filteredRole := role.withMembers(m["member"]).withIDs(m["id"]) if filteredRole != nil { @@ -93,8 +93,8 @@ func ListByQuery(l *ListRequest, m map[string][]string) { } } l.Value = &res - case *Policies: - var res Policies + case *[]Policy: + res := make([]Policy, 0) for _, policy := range *val { filteredPolicy := policy.withSubjects(m["subject"]).withResources(m["resource"]).withActions(m["action"]).withIDs(m["id"]) if filteredPolicy != nil {