mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
fix: make sure events are sorted
This commit is contained in:
parent
9e36f55aa4
commit
5d3381fc76
3 changed files with 14 additions and 2 deletions
|
@ -31,7 +31,7 @@ func RunRestCommand(c *gin.Context) {
|
||||||
func ShowRestEvents(c *gin.Context) {
|
func ShowRestEvents(c *gin.Context) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
events := session.I.Events.Events()
|
events := session.I.Events.Sorted()
|
||||||
nmax := len(events)
|
nmax := len(events)
|
||||||
n := nmax
|
n := nmax
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (s *EventsStream) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EventsStream) Show() error {
|
func (s *EventsStream) Show() error {
|
||||||
for _, e := range s.Session.Events.Events() {
|
for _, e := range s.Session.Events.Sorted() {
|
||||||
s.dumpEvent(e)
|
s.dumpEvent(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package session
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -96,3 +97,14 @@ func (p *EventPool) Events() []Event {
|
||||||
defer p.Unlock()
|
defer p.Unlock()
|
||||||
return p.events
|
return p.events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *EventPool) Sorted() []Event {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
|
sort.Slice(p.events, func(i, j int) bool {
|
||||||
|
return p.events[i].Time.Before(p.events[j].Time)
|
||||||
|
})
|
||||||
|
|
||||||
|
return p.events
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue