Skip to content

Commit

Permalink
sort results in List* api methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jan 17, 2022
1 parent 1a383bd commit 50378f0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions p2p/host/resource-manager/extapi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package rcmgr

import (
"bytes"
"sort"
"strings"

"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
Expand Down Expand Up @@ -56,6 +60,10 @@ func (r *resourceManager) ListServices() []string {
result = append(result, svc)
}

sort.Slice(result, func(i, j int) bool {
return strings.Compare(result[i], result[j]) < 0
})

return result
}

Expand All @@ -68,6 +76,10 @@ func (r *resourceManager) ListProtocols() []protocol.ID {
result = append(result, p)
}

sort.Slice(result, func(i, j int) bool {
return strings.Compare(string(result[i]), string(result[j])) < 0
})

return result
}

Expand All @@ -80,6 +92,10 @@ func (r *resourceManager) ListPeers() []peer.ID {
result = append(result, p)
}

sort.Slice(result, func(i, j int) bool {
return bytes.Compare([]byte(result[i]), []byte(result[j])) < 0
})

return result
}

Expand Down

0 comments on commit 50378f0

Please sign in to comment.