Skip to content

Commit

Permalink
enhance uniqueGrantID method
Browse files Browse the repository at this point in the history
  • Loading branch information
huamihe committed Apr 12, 2024
1 parent d3cf830 commit b53743a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,13 @@ func decodeACL(resp *Response, res *ACLXml) {
}

func uniqueGrantID(grantIDs []string) string {
res := []string{}
filter := make(map[string]int)
res := make([]string, 0, len(grantIDs))
filter := make(map[string]struct{})
for _, id := range grantIDs {
if filter[id] != 0 {
if _, ok := filter[id]; ok {
continue
}
filter[id] = 1
filter[id] = struct{}{}
res = append(res, id)
}
return strings.Join(res, ",")
Expand Down
8 changes: 8 additions & 0 deletions cos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,11 @@ func Test_SwitchHost(t *testing.T) {
}

}

func TestUniqueGrantID(t *testing.T) {
ids := []string{"abc", "abc", "ab"}
expect := uniqueGrantID(ids)
if expect != "abc,ab" {
t.Errorf("expect uniqueIDs to be abc,ab, got %v", expect)
}
}

0 comments on commit b53743a

Please sign in to comment.