go-log/mapping_router.go

29 lines
766 B
Go
Raw Normal View History

2015-10-11 05:21:58 +00:00
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))
}