EventRouter is a simple event routing library for Go. It allows you to bind handlers to routes and hooks to events, making it easy to manage and handle events in your application.
To install EventRouter, use go get:
go get github.com/pablor21/eventrouter
To create a new EventRouter, use the NewEventRouter function:
router := eventrouter.NewEventRouter()
You can bind handlers to routes using the Bind method:
handler := eventrouter.NewHandler("/test", func(e eventrouter.IEvent) error {
return nil
})
router.Bind(handler)
To unbind a handler from a route, use the Unbind method:
router.Unbind(handler)
You can bind hooks to handlers using the BindHook method:
hook:= eventrouter.NewHook(func(next eventrouter.HandlerFunc) eventrouter.HandlerFunc {
return func(e eventrouter.IEvent) error {
println("pre run called")
err := next(e)
if err != nil {
return err
}
println("hook called")
return nil
}
})
handler.BindHook(hook)
// you can also hook to the whole router
router.BindHook(hook)
To unbind a hook from an event, use the UnbindHook method:
router.UnbindHook(hook)
To handle an event, use the Handle method:
e := eventrouter.NewEvent("/test.1")
router.Handle(e)
To run the tests for this project, use the go test command:
go test ./...
This project is licensed under the MIT License. See the LICENSE file for details.