restore sortNetworks

This commit is contained in:
Matthew R Kasun 2023-04-19 14:06:39 -04:00
parent 57723b7aae
commit de111181bf
2 changed files with 9 additions and 0 deletions

View file

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

View file

@ -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 ==