sort results in List* api methods

This commit is contained in:
vyzo 2022-01-17 12:20:56 +02:00
parent 859d2061ea
commit 7523ae4614

View File

@ -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"
@ -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
}
@ -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
}
@ -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
}