Skip to content

Commit

Permalink
sort the program in xml request
Browse files Browse the repository at this point in the history
  • Loading branch information
test committed Aug 26, 2018
1 parent 41498ba commit d5ea22b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (s *Supervisor) GetAllProcessInfo(r *http.Request, args *struct{}, reply *s
procInfo := getProcessInfo(proc)
reply.AllProcessInfo = append(reply.AllProcessInfo, *procInfo)
})
types.SortProcessInfos( reply.AllProcessInfo )

return nil
}
Expand Down
33 changes: 33 additions & 0 deletions types/process-name-sorter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package types

import (
"sort"
"strings"
)

type ProcessNameSorter struct {
processes []ProcessInfo
}

func NewwProcessNameSorter(processes []ProcessInfo) *ProcessNameSorter {
return &ProcessNameSorter{processes: processes}
}

func (pns *ProcessNameSorter) Len() int {
return len(pns.processes)
}

func (pns *ProcessNameSorter) Less(i, j int) bool {
return strings.Compare(pns.processes[i].Name, pns.processes[j].Name) < 0
}

func (pns *ProcessNameSorter) Swap(i, j int) {
info := pns.processes[i]
pns.processes[i] = pns.processes[j]
pns.processes[j] = info
}

func SortProcessInfos(processes []ProcessInfo) {
sorter := NewwProcessNameSorter(processes)
sort.Sort(sorter)
}

0 comments on commit d5ea22b

Please sign in to comment.