Skip to content
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

toxiproxy-cli - sortedAttributes sort by attribute.key instead attribute.value #543

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
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