diff --git a/copying_router.go b/copying_router.go index b6eeba9..eadf5ee 100644 --- a/copying_router.go +++ b/copying_router.go @@ -27,6 +27,10 @@ type CopyingRouter struct { func (router *CopyingRouter) Route(message string, context map[string]interface{}) error { + if nil == router { + return errNilReceiver + } + copy := struct{Message string ; Context map[string]interface{}}{ Message: message, Context: context, diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..344fe9d --- /dev/null +++ b/errors.go @@ -0,0 +1,11 @@ +package flog + + +import ( + "errors" +) + + +var ( + errNilReceiver = errors.New("Nil Receiver") +) diff --git a/fanout_router.go b/fanout_router.go index dae08c2..5bf85d5 100644 --- a/fanout_router.go +++ b/fanout_router.go @@ -24,6 +24,10 @@ type FanoutRouter struct { func (router *FanoutRouter) Route(message string, context map[string]interface{}) error { + if nil == router { + return errNilReceiver + } + errors := []error{} for _, subrouter := range router.subrouters { diff --git a/filtering_router.go b/filtering_router.go index a44701b..e30985c 100644 --- a/filtering_router.go +++ b/filtering_router.go @@ -74,6 +74,10 @@ type FilteringRouter struct { func (router *FilteringRouter) Route(message string, context map[string]interface{}) error { + if nil == router { + return errNilReceiver + } + if router.filterFn(message, context) { return router.subrouter.Route(message, context) } diff --git a/mapping_router.go b/mapping_router.go index 064ac3b..cd32122 100644 --- a/mapping_router.go +++ b/mapping_router.go @@ -24,5 +24,9 @@ type MappingRouter struct { func (router *MappingRouter) Route(message string, context map[string]interface{}) error { + if nil == router { + return errNilReceiver + } + return router.subrouter.Route(router.fn(message, context)) } diff --git a/non_blocking_router.go b/non_blocking_router.go index a2381af..4590005 100644 --- a/non_blocking_router.go +++ b/non_blocking_router.go @@ -22,6 +22,10 @@ type NonBlockingRouter struct { func (router *NonBlockingRouter) Route(message string, context map[string]interface{}) error { + if nil == router { + return errNilReceiver + } + go func() { router.subrouter.Route(message, context) }() diff --git a/pretty_writing_router.go b/pretty_writing_router.go index 66cbcc3..742b4d8 100644 --- a/pretty_writing_router.go +++ b/pretty_writing_router.go @@ -34,6 +34,9 @@ type PrettyWritingRouter struct { func (router *PrettyWritingRouter) Route(message string, context map[string]interface{}) error { + if nil == router { + return errNilReceiver + } const STYLE_FATAL = "\x1b[40;33;1m" // BG BLACK, FG YELLOW, BOLD const STYLE_PANIC = "\x1b[40;31;1m" // BG BLACK, FG RED, BOLD