Skip to content

Commit bdc31f6

Browse files
author
huamihe
committed
enhance uniqueGrantID method
1 parent d3cf830 commit bdc31f6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

cos.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,13 @@ func decodeACL(resp *Response, res *ACLXml) {
627627
}
628628

629629
func uniqueGrantID(grantIDs []string) string {
630-
res := []string{}
631-
filter := make(map[string]int)
630+
res := make([]string, 0, len(grantIDs))
631+
filter := make(map[string]struct{})
632632
for _, id := range grantIDs {
633-
if filter[id] != 0 {
633+
if _, ok := filter[id]; ok {
634634
continue
635635
}
636-
filter[id] = 1
636+
filter[id] = struct{}{}
637637
res = append(res, id)
638638
}
639639
return strings.Join(res, ",")

cos_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,11 @@ func Test_SwitchHost(t *testing.T) {
231231
}
232232

233233
}
234+
235+
func TestUniqueGrantID(t *testing.T) {
236+
ids := []string{"abc", "abc", "ab"}
237+
actual := uniqueGrantID(ids)
238+
if actual != "abc,ab" {
239+
t.Errorf("expect uniqueIDs to be abc,ab, got %v", actual)
240+
}
241+
}

0 commit comments

Comments
 (0)