created mapping router

master
Charles Iliya Krempeaux 2015-10-10 22:21:58 -07:00
parent 55a0c662c6
commit dc2ac1bcf4
1 changed files with 28 additions and 0 deletions

28
mapping_router.go 100644
View File

@ -0,0 +1,28 @@
package flog
// NewMappingRouter returns an initialized MappingRouter.
func NewMappingRouter(subrouter Router, fn func(string, map[string]interface{})(string, map[string]interface{})) *MappingRouter {
router := MappingRouter{
subrouter:subrouter,
fn:fn,
}
return &router
}
// MappingRouter is a Router that can modify the message and context before
// re-routing it to its sub-router.
//
// Conceptually this is somewhat similar to "map" functions in functional
// programming.
type MappingRouter struct {
subrouter Router
fn func(string, map[string]interface{})(string, map[string]interface{})
}
func (router *MappingRouter) Route(message string, context map[string]interface{}) error {
return router.subrouter.Route(router.fn(message, context))
}