@@ -24,6 +24,7 @@ import (
2424
2525 "github.com/github/gh-aw/pkg/console"
2626 "github.com/github/gh-aw/pkg/logger"
27+ "github.com/github/gh-aw/pkg/sliceutil"
2728 "github.com/github/gh-aw/pkg/stringutil"
2829 "github.com/github/gh-aw/pkg/timeutil"
2930)
@@ -517,13 +518,7 @@ func renderGatewayMetricsTable(metrics *GatewayMetrics, verbose bool) string {
517518 output .WriteString ("├────────────────────────────┼──────────┼────────────┼───────────┼────────┤\n " )
518519
519520 // Sort servers by request count
520- var serverNames []string
521- for name := range metrics .Servers {
522- serverNames = append (serverNames , name )
523- }
524- sort .Slice (serverNames , func (i , j int ) bool {
525- return metrics.Servers [serverNames [i ]].RequestCount > metrics.Servers [serverNames [j ]].RequestCount
526- })
521+ serverNames := getSortedServerNames (metrics )
527522
528523 for _ , serverName := range serverNames {
529524 server := metrics .Servers [serverName ]
@@ -560,10 +555,7 @@ func renderGatewayMetricsTable(metrics *GatewayMetrics, verbose bool) string {
560555 output .WriteString ("├──────────────────────────┼───────┼──────────┼──────────┼──────────┤\n " )
561556
562557 // Sort tools by call count
563- var toolNames []string
564- for name := range server .Tools {
565- toolNames = append (toolNames , name )
566- }
558+ toolNames := sliceutil .MapToSlice (server .Tools )
567559 sort .Slice (toolNames , func (i , j int ) bool {
568560 return server.Tools [toolNames [i ]].CallCount > server.Tools [toolNames [j ]].CallCount
569561 })
@@ -587,10 +579,7 @@ func renderGatewayMetricsTable(metrics *GatewayMetrics, verbose bool) string {
587579
588580// getSortedServerNames returns server names sorted by request count
589581func getSortedServerNames (metrics * GatewayMetrics ) []string {
590- var names []string
591- for name := range metrics .Servers {
592- names = append (names , name )
593- }
582+ names := sliceutil .MapToSlice (metrics .Servers )
594583 sort .Slice (names , func (i , j int ) bool {
595584 return metrics.Servers [names [i ]].RequestCount > metrics.Servers [names [j ]].RequestCount
596585 })
0 commit comments