...
1
2
3
4
5
6 package core
7
8 import (
9 "fmt"
10 "time"
11
12 "golang.org/x/tools/internal/event/label"
13 )
14
15
16 type Event struct {
17 at time.Time
18
19
20
21
22
23
24
25
26
27 static [3]label.Label
28 dynamic []label.Label
29 }
30
31
32 type eventLabelMap struct {
33 event Event
34 }
35
36 func (ev Event) At() time.Time { return ev.at }
37
38 func (ev Event) Format(f fmt.State, r rune) {
39 if !ev.at.IsZero() {
40 fmt.Fprint(f, ev.at.Format("2006/01/02 15:04:05 "))
41 }
42 for index := 0; ev.Valid(index); index++ {
43 if l := ev.Label(index); l.Valid() {
44 fmt.Fprintf(f, "\n\t%v", l)
45 }
46 }
47 }
48
49 func (ev Event) Valid(index int) bool {
50 return index >= 0 && index < len(ev.static)+len(ev.dynamic)
51 }
52
53 func (ev Event) Label(index int) label.Label {
54 if index < len(ev.static) {
55 return ev.static[index]
56 }
57 return ev.dynamic[index-len(ev.static)]
58 }
59
60 func (ev Event) Find(key label.Key) label.Label {
61 for _, l := range ev.static {
62 if l.Key() == key {
63 return l
64 }
65 }
66 for _, l := range ev.dynamic {
67 if l.Key() == key {
68 return l
69 }
70 }
71 return label.Label{}
72 }
73
74 func MakeEvent(static [3]label.Label, labels []label.Label) Event {
75 return Event{
76 static: static,
77 dynamic: labels,
78 }
79 }
80
81
82 func CloneEvent(ev Event, at time.Time) Event {
83 ev.at = at
84 return ev
85 }
86
View as plain text