Esempio n. 1
0
func newEventSource(evm event.EventManager) eventsource.EventSource {
	es := eventsource.New(nil, nil)

	var id int = -1
	evm.Bind(event.AllEvents, func(es eventsource.EventSource, ev event.Event) {
		id++
		data, _ := json.Marshal(ev.Data)
		go es.SendEventMessage(string(data), string(ev.Type), strconv.Itoa(id))
	})

	return es
}
Esempio n. 2
0
func newEventTracer(evm event.EventManager) *eventTracer {
	t := &eventTracer{25, make(map[event.EventType][]map[string]interface{}, 0)}
	evm.Bind(event.AllEvents, func(ev event.Event) {
		history, ok := t.data[ev.Type]
		if !ok {
			history = make([]map[string]interface{}, 0)
		}

		if len(history) >= t.limit {
			history = history[1:]
		}

		history = append(history, ev.Data)

		t.data[ev.Type] = history
	})

	return t
}