Skip to content

Commit

Permalink
code clean
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed Apr 19, 2024
1 parent 0f5c08e commit 738a06c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions kong/router/transform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -710,27 +710,30 @@ local function split_routes_and_services_by_path(routes_and_services)
assert(tb_nkeys(route_and_service) == 1 or tb_nkeys(route_and_service) == 2)

local original_route_id = original_route.id
local original_service = route_and_service.service
local grouped_paths = group_by(original_paths, sort_by_regex_or_length)

local is_first = true
for idx, paths in pairs(grouped_paths) do
local cloned_route = {
route = shallow_copy(original_route),
service = route_and_service.service,
}
local route = shallow_copy(original_route)

route.original_route = original_route
route.paths = paths
route.id = uuid_generator(original_route_id .. "#" .. tostring(idx))

cloned_route.route.original_route = original_route
cloned_route.route.paths = paths
cloned_route.route.id = uuid_generator(original_route_id .. "#" .. tostring(idx))
local cloned_route_and_service = {
route = route,
service = original_service,
}

if is_first then
-- the first one will replace the original route
routes_and_services[i] = cloned_route
routes_and_services[i] = cloned_route_and_service
is_first = false

else
-- the others will append to the original routes array
routes_and_services[count + append_count] = cloned_route
routes_and_services[count + append_count] = cloned_route_and_service
append_count = append_count + 1
end
end -- for pairs(grouped_paths)
Expand Down

0 comments on commit 738a06c

Please sign in to comment.