WrapProcessor takes an existing TProcessor and wraps each of its inner TProcessorFunctions with the middlewares passed in and returns it. Middlewares will be called in the order that they are defined: 1. Middlewares[0] 2. Middlewares[1] ... N. Middlewares[n]
(processor TProcessor, middlewares ...ProcessorMiddleware)
| 40 | // ... |
| 41 | // N. Middlewares[n] |
| 42 | func WrapProcessor(processor TProcessor, middlewares ...ProcessorMiddleware) TProcessor { |
| 43 | for name, processorFunc := range processor.ProcessorMap() { |
| 44 | wrapped := processorFunc |
| 45 | // Add middlewares in reverse so the first in the list is the outermost. |
| 46 | for i := len(middlewares) - 1; i >= 0; i-- { |
| 47 | wrapped = middlewares[i](name, wrapped) |
| 48 | } |
| 49 | processor.AddToProcessorMap(name, wrapped) |
| 50 | } |
| 51 | return processor |
| 52 | } |
| 53 | |
| 54 | // WrappedTProcessorFunction is a convenience struct that implements the |
| 55 | // TProcessorFunction interface that can be used when implementing custom |