Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
25 lines (21 sloc) 448 Bytes
package events
import (
"regexp"
"github.com/gobuffalo/events/internal/safe"
)
// Filter compiles the string as a regex and returns
// the original listener wrapped in a new listener
// that filters incoming events by the Kind
func Filter(s string, fn Listener) Listener {
if s == "" || s == "*" {
return fn
}
rx := regexp.MustCompile(s)
return func(e Event) {
if rx.MatchString(e.Kind) {
safe.Run(func() {
fn(e)
})
}
}
}
You can’t perform that action at this time.