NewEvent creates a new event, but does not emit the event. To emit an event, call Emit() on the current instance of the caddyevents app instead. EXPERIMENTAL: Subject to change.
(ctx Context, name string, data map[string]any)
| 1133 | // |
| 1134 | // EXPERIMENTAL: Subject to change. |
| 1135 | func NewEvent(ctx Context, name string, data map[string]any) (Event, error) { |
| 1136 | id, err := uuid.NewRandom() |
| 1137 | if err != nil { |
| 1138 | return Event{}, fmt.Errorf("generating new event ID: %v", err) |
| 1139 | } |
| 1140 | name = strings.ToLower(name) |
| 1141 | return Event{ |
| 1142 | Data: data, |
| 1143 | id: id, |
| 1144 | ts: time.Now(), |
| 1145 | name: name, |
| 1146 | origin: ctx.Module(), |
| 1147 | }, nil |
| 1148 | } |
| 1149 | |
| 1150 | func (e Event) ID() uuid.UUID { return e.id } |
| 1151 | func (e Event) Timestamp() time.Time { return e.ts } |