mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
new: implemented GET /api/events route (ref #5).
This commit is contained in:
parent
ee4b783015
commit
269d7d845b
14 changed files with 172 additions and 38 deletions
53
session/events.go
Normal file
53
session/events.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
Tag string `json:"tag"`
|
||||
Time time.Time `json:"time"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func NewEvent(tag string, data interface{}) Event {
|
||||
return Event{
|
||||
Tag: tag,
|
||||
Time: time.Now(),
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func (e Event) Print() {
|
||||
fmt.Printf("[%s] [%s] [%s] %+v\n", e.Time, core.Bold("event"), core.Green(e.Tag), e.Data)
|
||||
}
|
||||
|
||||
type EventPool struct {
|
||||
events []Event
|
||||
lock *sync.Mutex
|
||||
}
|
||||
|
||||
func NewEventPool() *EventPool {
|
||||
return &EventPool{
|
||||
events: make([]Event, 0),
|
||||
lock: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EventPool) Add(tag string, data interface{}) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
e := NewEvent(tag, data)
|
||||
p.events = append([]Event{e}, p.events...)
|
||||
e.Print()
|
||||
}
|
||||
|
||||
func (p *EventPool) Events() []Event {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
return p.events
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue