Skip to content

enhance uniqueGrantID method #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}
actual := uniqueGrantID(ids)
if actual != "abc,ab" {
t.Errorf("expect uniqueIDs to be abc,ab, got %v", actual)
}
}