Skip to content

Commit

Permalink
Sorts sessions when printed
Browse files Browse the repository at this point in the history
  • Loading branch information
nodauf committed Mar 30, 2021
1 parent 6b61132 commit f6059f0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/sessions/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sessions
import (
"fmt"
"os"
"sort"
"strconv"

logging "github.com/op/go-logging"
Expand All @@ -20,7 +21,14 @@ var OptionsSession Options

// PrintSessions will list all active sessions
func PrintSessions() {
for id, terminal := range sessions {
// Tricks to print the map ordered by ID
keys := make([]int, 0, len(sessions))
for k := range sessions {
keys = append(keys, k)
}
sort.Ints(keys)
for _, id := range keys {
terminal := sessions[id]
fmt.Println(strconv.Itoa(id) + " => " + terminal.OS + " " + terminal.Con.RemoteAddr().String())
}
}
Expand Down

0 comments on commit f6059f0

Please sign in to comment.