fix(go): sort directly;

This commit is contained in:
Vishal Dalwadi 2025-07-30 22:50:37 +05:30
parent f4ab479593
commit 1337b63816

View file

@ -5,7 +5,10 @@ import (
"github.com/gorilla/mux"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
"net/http"
"slices"
"strings"
)
func NetworkHandlers(r *mux.Router) {
@ -25,7 +28,9 @@ func getNetworkGraph(w http.ResponseWriter, r *http.Request) {
networkNodes = logic.AddStaticNodestoList(networkNodes)
// return all the nodes in JSON/API format
apiNodes := logic.GetAllNodesAPIWithLocation(networkNodes[:])
logic.SortApiNodes(apiNodes[:])
slices.SortFunc(apiNodes, func(a, b models.ApiNode) int {
return strings.Compare(a.ID, b.ID)
})
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(apiNodes)
}