made it so that the Route() methods, of the various routers, will return an error if the receiver is nil. (except for the discard router.)
parent
34b5f0d3fe
commit
4afa358cf7
|
@ -27,6 +27,10 @@ type CopyingRouter struct {
|
||||||
|
|
||||||
|
|
||||||
func (router *CopyingRouter) Route(message string, context map[string]interface{}) error {
|
func (router *CopyingRouter) Route(message string, context map[string]interface{}) error {
|
||||||
|
if nil == router {
|
||||||
|
return errNilReceiver
|
||||||
|
}
|
||||||
|
|
||||||
copy := struct{Message string ; Context map[string]interface{}}{
|
copy := struct{Message string ; Context map[string]interface{}}{
|
||||||
Message: message,
|
Message: message,
|
||||||
Context: context,
|
Context: context,
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package flog
|
||||||
|
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
var (
|
||||||
|
errNilReceiver = errors.New("Nil Receiver")
|
||||||
|
)
|
|
@ -24,6 +24,10 @@ type FanoutRouter struct {
|
||||||
|
|
||||||
|
|
||||||
func (router *FanoutRouter) Route(message string, context map[string]interface{}) error {
|
func (router *FanoutRouter) Route(message string, context map[string]interface{}) error {
|
||||||
|
if nil == router {
|
||||||
|
return errNilReceiver
|
||||||
|
}
|
||||||
|
|
||||||
errors := []error{}
|
errors := []error{}
|
||||||
|
|
||||||
for _, subrouter := range router.subrouters {
|
for _, subrouter := range router.subrouters {
|
||||||
|
|
|
@ -74,6 +74,10 @@ type FilteringRouter struct {
|
||||||
|
|
||||||
|
|
||||||
func (router *FilteringRouter) Route(message string, context map[string]interface{}) error {
|
func (router *FilteringRouter) Route(message string, context map[string]interface{}) error {
|
||||||
|
if nil == router {
|
||||||
|
return errNilReceiver
|
||||||
|
}
|
||||||
|
|
||||||
if router.filterFn(message, context) {
|
if router.filterFn(message, context) {
|
||||||
return router.subrouter.Route(message, context)
|
return router.subrouter.Route(message, context)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,9 @@ type MappingRouter struct {
|
||||||
|
|
||||||
|
|
||||||
func (router *MappingRouter) Route(message string, context map[string]interface{}) error {
|
func (router *MappingRouter) Route(message string, context map[string]interface{}) error {
|
||||||
|
if nil == router {
|
||||||
|
return errNilReceiver
|
||||||
|
}
|
||||||
|
|
||||||
return router.subrouter.Route(router.fn(message, context))
|
return router.subrouter.Route(router.fn(message, context))
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,10 @@ type NonBlockingRouter struct {
|
||||||
|
|
||||||
|
|
||||||
func (router *NonBlockingRouter) Route(message string, context map[string]interface{}) error {
|
func (router *NonBlockingRouter) Route(message string, context map[string]interface{}) error {
|
||||||
|
if nil == router {
|
||||||
|
return errNilReceiver
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
router.subrouter.Route(message, context)
|
router.subrouter.Route(message, context)
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -34,6 +34,9 @@ type PrettyWritingRouter struct {
|
||||||
|
|
||||||
|
|
||||||
func (router *PrettyWritingRouter) Route(message string, context map[string]interface{}) error {
|
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_FATAL = "\x1b[40;33;1m" // BG BLACK, FG YELLOW, BOLD
|
||||||
const STYLE_PANIC = "\x1b[40;31;1m" // BG BLACK, FG RED, BOLD
|
const STYLE_PANIC = "\x1b[40;31;1m" // BG BLACK, FG RED, BOLD
|
||||||
|
|
Loading…
Reference in New Issue