Skip to content

Commit

Permalink
fix: use make() to initialize slices (#250)
Browse files Browse the repository at this point in the history
Closes #217
  • Loading branch information
xlanor authored Oct 3, 2020
1 parent c671f73 commit 84f028d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions engine/ladon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions storage/filter_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var (
Members: []string{"mem1", "mem2"},
},
},
nil,
Roles{},
rolReq,
rolReq,
rolReq,
Expand Down Expand Up @@ -93,7 +93,7 @@ var (
Resources: []string{"res1", "res2"},
},
},
nil,
nil,
Policies{},
Policies{},
}
)
4 changes: 2 additions & 2 deletions storage/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 84f028d

Please sign in to comment.