Open penguwin opened 4 years ago
force pushed some fixed typos in my comments
It's a matter of preference, but I'm ok with the existing code if that helps. It's explicit, making it easier to understand what kind of types are being sent in each event when reading the code. A bit less magical.
I agree that the existing code is less magical and also more explicit about the types. Yet the EventDescriptor
already contains the type-information for each placeholder which makes it a bit redundant to have to also declare it for every placeholder in the Event
itself.
On second thought, I realized that not using the code from this pr would be in favour of the KISS principle - there should be only one consistent way to declare the events (even if it's more verbose). Therefore I'd also say that we should rather not merge this pr. Any final thoughts @muesli?
p.s. after looking at the code again I also noticed that I should probably break the loop in CreateEvent
after appending each Placeholder to the Event - and also return an error if no placeholders were created instead of just returning an empty event.
This adds a new
createEvent()
method on the implemented Bees which handles back a filledEvent
-Struct for the given Eventname and map of Placholder values.The map for the Placeholders should be structured like this:
With a map like this you can simply trigger an event like so:
I also demonstrated the usage in
openweathermapbee/event.go
and in theircbee.go
and as you can see this reduces the amount of code we have to write.