renamed FilteredRouter to FilteringRouter

master
Charles Iliya Krempeaux 2015-10-10 14:13:34 -07:00
parent 9745ffaaec
commit a7db62302f
2 changed files with 12 additions and 12 deletions

View File

@ -1,9 +1,9 @@
package flog 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 // re-Route a 'message' (and 'context') to, but only on the
// condition that 'filterFn' returns 'true' for the 'message' // condition that 'filterFn' returns 'true' for the 'message'
// and 'context' passed to it. // and 'context' passed to it.
@ -56,8 +56,8 @@ package flog
// return true // return true
// } // }
// //
func NewFilteredRouter(subrouter Router, filterFn func(string, map[string]interface{})bool) *FilteredRouter { func NewFilteringRouter(subrouter Router, filterFn func(string, map[string]interface{})bool) *FilteringRouter {
router := FilteredRouter{ router := FilteringRouter{
subrouter:subrouter, subrouter:subrouter,
filterFn:filterFn, 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). // FilteringRouter is a Router that conditionally re-routes or discards a message (and its context).
type FilteredRouter struct { type FilteringRouter struct {
subrouter Router subrouter Router
filterFn func(string, map[string]interface{})bool 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) { if router.filterFn(message, context) {
return router.subrouter.Route(message, context) return router.subrouter.Route(message, context)
} }

View File

@ -10,16 +10,16 @@ import (
) )
func TestFilteredRouterJustCreated(t *testing.T) { func TestFilteringRouterJustCreated(t *testing.T) {
randomness := rand.New(rand.NewSource( time.Now().UTC().UnixNano() )) 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 return false
}) })
if nil == router { 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() )) randomness := rand.New(rand.NewSource( time.Now().UTC().UnixNano() ))
@ -44,7 +44,7 @@ func TestFilteredRouterJustFilterParameters(t *testing.T) {
var filterContext map[string] interface{} var filterContext map[string] interface{}
var filterResult = false 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 filterMessage = message
filterContext = context filterContext = context