-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevents.go
More file actions
55 lines (46 loc) · 952 Bytes
/
events.go
File metadata and controls
55 lines (46 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package procwatch
import (
"fmt"
"strings"
"time"
"github.com/ghetzel/go-stockutil/sliceutil"
)
type EventSource int
const (
ProgramSource EventSource = iota
)
func (src EventSource) String() string {
switch src {
case ProgramSource:
return `Program`
default:
return `Anonymous`
}
}
type Event struct {
Names []string
Label string
Timestamp time.Time
Error error
Arguments []string
SourceType EventSource
Source any
}
func NewEvent(names []string, label string, sourceType EventSource, source any, args ...string) *Event {
return &Event{
Names: names,
Label: label,
Timestamp: time.Now(),
Arguments: args,
SourceType: sourceType,
Source: source,
}
}
func (event *Event) String() string {
return fmt.Sprintf("[%s] %s",
event.Label,
strings.Join(event.Names, `,`))
}
func (event *Event) HasName(name string) bool {
return sliceutil.ContainsString(event.Names, name)
}