add the concept of routes input/output

This commit is contained in:
Joel Wetzell
2025-11-19 18:33:04 -06:00
parent 8e0f25abe9
commit 0e903eba2f
11 changed files with 193 additions and 35 deletions

32
route.go Normal file
View File

@@ -0,0 +1,32 @@
package showbridge
import "log/slog"
type Route struct {
index int
Input string
Output string
router *Router
}
type RouteConfig struct {
Input string `json:"input"`
Output string `json:"output"`
}
func NewRoute(index int, config RouteConfig, router *Router) *Route {
return &Route{Input: config.Input, Output: config.Output, router: router, index: index}
}
func (r *Route) HandleInput(sourceId string, payload any) {
slog.Debug("route input", "index", r.index, "source", sourceId, "payload", payload)
r.HandleOutput(payload)
}
func (r *Route) HandleOutput(payload any) {
slog.Debug("route output", "index", r.index, "destination", r.Output, "payload", payload)
err := r.router.HandleOutput(r.Output, payload)
if err != nil {
slog.Error("problem with route output", "error", err.Error())
}
}