Skip to content

Commit

Permalink
sortedAttributes sort by Key instead of value
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseward committed Nov 13, 2023
1 parent 7abcb6f commit 85c1d6f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,16 +619,15 @@ type attribute struct {

type attributeList []attribute

func (a attributeList) Len() int { return len(a) }
func (a attributeList) Less(i, j int) bool { return a[i].key < a[j].key }
func (a attributeList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func sortedAttributes(attrs toxiproxy.Attributes) attributeList {
li := make(attributeList, 0, len(attrs))
for k, v := range attrs {
li = append(li, attribute{k, v.(float64)})
li = append(li, attribute{k, v})
}
sort.Sort(li)
sort.Slice(li, func(i, j int) bool {
return li[i].key < li[j].key
})

return li
}

Expand Down

0 comments on commit 85c1d6f

Please sign in to comment.