From 388851f8bd35f8acc700b78313458ab6f05e62b7 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sat, 6 Dec 2025 23:08:05 -0600 Subject: [PATCH] inject router on HandleInput --- route.go | 15 +++++++-------- router.go | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/route.go b/route.go index deb2656..f2f11cc 100644 --- a/route.go +++ b/route.go @@ -18,10 +18,9 @@ type Route struct { Input string Processors []processing.Processor Output string - router *Router } -func NewRoute(index int, config config.RouteConfig, router *Router) (*Route, error) { +func NewRoute(index int, config config.RouteConfig) (*Route, error) { processors := []processing.Processor{} if len(config.Processors) > 0 { @@ -39,13 +38,13 @@ func NewRoute(index int, config config.RouteConfig, router *Router) (*Route, err } } - return &Route{Input: config.Input, Processors: processors, Output: config.Output, router: router, index: index}, nil + return &Route{Input: config.Input, Processors: processors, Output: config.Output, index: index}, nil } -func (r *Route) HandleInput(sourceId string, payload any) error { +func (r *Route) HandleInput(sourceId string, payload any, router *Router) error { var err error for _, processor := range r.Processors { - payload, err = processor.Process(r.router.Context, payload) + payload, err = processor.Process(router.Context, payload) if err != nil { return err } @@ -54,9 +53,9 @@ func (r *Route) HandleInput(sourceId string, payload any) error { return nil } } - return r.HandleOutput(sourceId, payload) + return r.HandleOutput(sourceId, payload, router) } -func (r *Route) HandleOutput(sourceId string, payload any) error { - return r.router.HandleOutput(sourceId, r.Output, payload) +func (r *Route) HandleOutput(sourceId string, payload any, router *Router) error { + return router.HandleOutput(sourceId, r.Output, payload) } diff --git a/router.go b/router.go index 4fedd10..8f488d8 100644 --- a/router.go +++ b/router.go @@ -95,7 +95,7 @@ func NewRouter(ctx context.Context, config config.Config) (*Router, []ModuleErro var routeErrors []RouteError for routeIndex, routeDecl := range config.Routes { - route, err := NewRoute(routeIndex, routeDecl, &router) + route, err := NewRoute(routeIndex, routeDecl) if err != nil { if routeErrors == nil { routeErrors = []RouteError{} @@ -138,7 +138,7 @@ func (r *Router) HandleInput(sourceId string, payload any) []RoutingError { var routingErrors []RoutingError for routeIndex, route := range r.RouteInstances { if route.Input == sourceId { - err := route.HandleInput(sourceId, payload) + err := route.HandleInput(sourceId, payload, r) if err != nil { if routingErrors == nil { routingErrors = []RoutingError{}