added to docs

master
Charles Iliya Krempeaux 2015-10-10 13:35:41 -07:00
parent 4b4695769b
commit cb7d7586b8
1 changed files with 31 additions and 0 deletions

View File

@ -7,6 +7,37 @@ package flog
// re-Route a 'message' (and 'context') to, but only on the // re-Route a 'message' (and 'context') to, but only on the
// condition that 'filterFn' returns 'true' for the 'message' // condition that 'filterFn' returns 'true' for the 'message'
// and 'context' passed to it. // and 'context' passed to it.
//
// An example for 'filterFn' is the following.
//
// func filterError(message string, context map[string]interface{})bool) bool {
// if datum, ok := context["error"]; !ok {
// return false
// } else if _, ok := datum.(error); !ok {
// return false
// } else {
// return true
// }
// }
//
// This func will make it so only re-route messages whose context #1 has the key "error"
// and #2 the value of the context at key "key" fits the builtin Go 'error' interface.
//
// Also, a rather useless example, but a 'filterFn' that would reject all messages (and
// contexts) is:
//
// func filterRejectAll(message string, context map[string]interface{})bool) bool {
// return false
// }
//
//
// And also, another rather useless example, but a 'filterFn' that would allow all messages
// (and contexts) is:
//
// func filterAcceptAll(message string, context map[string]interface{})bool) bool {
// return true
// }
//
func NewFilteredRouter(subrouter Router, filterFn func(string, map[string]interface{})bool) *FilteredRouter { func NewFilteredRouter(subrouter Router, filterFn func(string, map[string]interface{})bool) *FilteredRouter {
router := FilteredRouter{ router := FilteredRouter{
subrouter:subrouter, subrouter:subrouter,