mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-12 16:14:37 +08:00
restore sortNetworks
This commit is contained in:
parent
57723b7aae
commit
de111181bf
2 changed files with 9 additions and 0 deletions
|
@ -69,6 +69,7 @@ func getNetworks(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
logger.Log(2, r.Header.Get("user"), "fetched networks.")
|
||||
logic.SortNetworks(allnetworks[:])
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(allnetworks)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/c-robinson/iplib"
|
||||
|
@ -577,4 +578,11 @@ func NetworkExists(name string) (bool, error) {
|
|||
return len(network) > 0, nil
|
||||
}
|
||||
|
||||
// SortNetworks - Sorts slice of Networks by their NetID alphabetically with numbers first
|
||||
func SortNetworks(unsortedNetworks []models.Network) {
|
||||
sort.Slice(unsortedNetworks, func(i, j int) bool {
|
||||
return unsortedNetworks[i].NetID < unsortedNetworks[j].NetID
|
||||
})
|
||||
}
|
||||
|
||||
// == Private ==
|
||||
|
|
Loading…
Add table
Reference in a new issue