From dc2ac1bcf45ceaf9fb013ab23b97a6247b7f9532 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sat, 10 Oct 2015 22:21:58 -0700 Subject: [PATCH] created mapping router --- mapping_router.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 mapping_router.go diff --git a/mapping_router.go b/mapping_router.go new file mode 100644 index 0000000..064ac3b --- /dev/null +++ b/mapping_router.go @@ -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)) +}