renamed FilteredRouter to FilteringRouter
parent
9745ffaaec
commit
a7db62302f
|
@ -1,9 +1,9 @@
|
|||
package flog
|
||||
|
||||
|
||||
// NewFilteredRouter returns an initialized FilteredRouter.
|
||||
// NewFilteringRouter returns an initialized FilteringRouter.
|
||||
//
|
||||
// 'subrouter' is the sub-router that a FilteredRouter will
|
||||
// 'subrouter' is the sub-router that a FilteringRouter will
|
||||
// re-Route a 'message' (and 'context') to, but only on the
|
||||
// condition that 'filterFn' returns 'true' for the 'message'
|
||||
// and 'context' passed to it.
|
||||
|
@ -56,8 +56,8 @@ package flog
|
|||
// return true
|
||||
// }
|
||||
//
|
||||
func NewFilteredRouter(subrouter Router, filterFn func(string, map[string]interface{})bool) *FilteredRouter {
|
||||
router := FilteredRouter{
|
||||
func NewFilteringRouter(subrouter Router, filterFn func(string, map[string]interface{})bool) *FilteringRouter {
|
||||
router := FilteringRouter{
|
||||
subrouter:subrouter,
|
||||
filterFn:filterFn,
|
||||
}
|
||||
|
@ -66,14 +66,14 @@ func NewFilteredRouter(subrouter Router, filterFn func(string, map[string]interf
|
|||
}
|
||||
|
||||
|
||||
// FilteredRouter is a Router that conditionally re-routes or discards a message (and its context).
|
||||
type FilteredRouter struct {
|
||||
// FilteringRouter is a Router that conditionally re-routes or discards a message (and its context).
|
||||
type FilteringRouter struct {
|
||||
subrouter Router
|
||||
filterFn func(string, map[string]interface{})bool
|
||||
}
|
||||
|
||||
|
||||
func (router *FilteredRouter) Route(message string, context map[string]interface{}) error {
|
||||
func (router *FilteringRouter) Route(message string, context map[string]interface{}) error {
|
||||
if router.filterFn(message, context) {
|
||||
return router.subrouter.Route(message, context)
|
||||
}
|
||||
|
|
|
@ -10,16 +10,16 @@ import (
|
|||
)
|
||||
|
||||
|
||||
func TestFilteredRouterJustCreated(t *testing.T) {
|
||||
func TestFilteringRouterJustCreated(t *testing.T) {
|
||||
|
||||
randomness := rand.New(rand.NewSource( time.Now().UTC().UnixNano() ))
|
||||
|
||||
|
||||
router := NewFilteredRouter(NewDiscardRouter(), func(string, map[string]interface{}) bool {
|
||||
router := NewFilteringRouter(NewDiscardRouter(), func(string, map[string]interface{}) bool {
|
||||
return false
|
||||
})
|
||||
if nil == router {
|
||||
t.Errorf("After trying to create a filtered router, expected it to be not nil, but was: %v", router)
|
||||
t.Errorf("After trying to create a filtering router, expected it to be not nil, but was: %v", router)
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,7 +35,7 @@ func TestFilteredRouterJustCreated(t *testing.T) {
|
|||
}
|
||||
|
||||
|
||||
func TestFilteredRouterJustFilterParameters(t *testing.T) {
|
||||
func TestFilteringRouterJustFilterParameters(t *testing.T) {
|
||||
|
||||
randomness := rand.New(rand.NewSource( time.Now().UTC().UnixNano() ))
|
||||
|
||||
|
@ -44,7 +44,7 @@ func TestFilteredRouterJustFilterParameters(t *testing.T) {
|
|||
var filterContext map[string] interface{}
|
||||
var filterResult = false
|
||||
|
||||
router := NewFilteredRouter(NewDiscardRouter(), func(message string, context map[string]interface{}) bool {
|
||||
router := NewFilteringRouter(NewDiscardRouter(), func(message string, context map[string]interface{}) bool {
|
||||
filterMessage = message
|
||||
filterContext = context
|
||||
|
||||
|
|
Loading…
Reference in New Issue