diff --git a/engine/ladon/handler.go b/engine/ladon/handler.go index e3e7b3e02..174f715f9 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.Roles, 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.Policies, 0) f, err := flavor(ps) if err != nil { return nil, err diff --git a/storage/filter_helper_test.go b/storage/filter_helper_test.go index 8749fda8f..e8b9ff30d 100644 --- a/storage/filter_helper_test.go +++ b/storage/filter_helper_test.go @@ -52,7 +52,7 @@ var ( Members: []string{"mem1", "mem2"}, }, }, - nil, + Roles{}, rolReq, rolReq, rolReq, @@ -93,7 +93,7 @@ var ( Resources: []string{"res1", "res2"}, }, }, - nil, - nil, + Policies{}, + Policies{}, } ) diff --git a/storage/handler.go b/storage/handler.go index 9949e1dee..6f3dc10c1 100644 --- a/storage/handler.go +++ b/storage/handler.go @@ -85,7 +85,7 @@ 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 + res := make(Roles, 0) for _, role := range *val { filteredRole := role.withMembers(m["member"]).withIDs(m["id"]) if filteredRole != nil { @@ -94,7 +94,7 @@ func ListByQuery(l *ListRequest, m map[string][]string) { } l.Value = &res case *Policies: - var res Policies + res := make(Policies, 0) for _, policy := range *val { filteredPolicy := policy.withSubjects(m["subject"]).withResources(m["resource"]).withActions(m["action"]).withIDs(m["id"]) if filteredPolicy != nil {