Eventable

To make module Eventable add function GetEventFuncs() to your main.go

.
.
.

func (m module) GetEventFuncs() []eather.Fire {
	return eventFuncs
}

var eventFuncs = []eather.Fire{
	eather.Fire{Call: "added", Func: added},
	eather.Fire{Call: "removed", Func: removed},
}

var added = func(data ...interface{}) {
	fmt.Println(data)
	time.Sleep(2 * time.Second)
	fmt.Println("Running event after added")
}

var removed = func(data ...interface{}) {
	fmt.Println(data)
	time.Sleep(2 * time.Second)
	fmt.Println("Running event after removed")
}


.
.
.

And add to module.xml listeners for this events

<?xml version="1.0" encoding="UTF-8"?>
<module>
    <name>Empty</name>
    <version>1.0.0</version>
    <events>
        <listener for="test_added" call="added" name="add_some_stuff"></listener>
        <listener for="test_removed" call="removed" name="remove_some_stuff"></listener>
    </events>
</module>

Now your functions added can be triggered by calling eather.GetEvents().Emmit("test_added", map[string]interface{}{"code": "test_code"})

Last updated