From 2bf35aa636da4570d7d6e135ee2892aa185c14ca Mon Sep 17 00:00:00 2001 From: Sean Rankine Date: Wed, 23 Oct 2024 11:48:35 +0100 Subject: [PATCH] Change shouldPreserveSegements to work with CsRoute This allows the function be used with either CsRoute or the existing Route type. --- lib/router.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/router.go b/lib/router.go index d7890ce6..126e2740 100644 --- a/lib/router.go +++ b/lib/router.go @@ -322,7 +322,7 @@ func loadRoutes(c *mgo.Collection, mux *triemux.Mux, backends map[string]http.Ha logDebug(fmt.Sprintf("router: registered %s (prefix: %v) for %s", incomingURL.Path, prefix, route.BackendID)) case "redirect": - handler := handlers.NewRedirectHandler(incomingURL.Path, route.RedirectTo, shouldPreserveSegments(route)) + handler := handlers.NewRedirectHandler(incomingURL.Path, route.RedirectTo, shouldPreserveSegments(route.RouteType, route.SegmentsMode)) mux.Handle(incomingURL.Path, prefix, handler) logDebug(fmt.Sprintf("router: registered %s (prefix: %v) -> %s", incomingURL.Path, prefix, route.RedirectTo)) @@ -347,12 +347,12 @@ func loadRoutes(c *mgo.Collection, mux *triemux.Mux, backends map[string]http.Ha } } -func shouldPreserveSegments(route *Route) bool { - switch route.RouteType { +func shouldPreserveSegments(routeType, segmentsMode string) bool { + switch routeType { case RouteTypeExact: - return route.SegmentsMode == SegmentsModePreserve + return segmentsMode == SegmentsModePreserve case RouteTypePrefix: - return route.SegmentsMode != SegmentsModeIgnore + return segmentsMode != SegmentsModeIgnore default: return false }