Skip to content

Commit

Permalink
style(router): rename buffer_append to expression_append (#11277)
Browse files Browse the repository at this point in the history
Apply the suggestion in #11071 (comment).

KAG-2148
  • Loading branch information
chronolaw authored Jul 31, 2023
1 parent 33dbd4f commit cbcddf2
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions kong/router/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ local single_header_buf = buffer.new(64)
-- sep: a seperator of expressions, like '&&'
-- idx: indicate whether or not to add 'sep'
-- for example, we should not add 'sep' for the first element in array
local function buffer_append(buf, sep, str, idx)
local function expression_append(buf, sep, str, idx)
if #buf > 0 and
(idx == nil or idx > 1)
then
Expand Down Expand Up @@ -118,17 +118,17 @@ local function gen_for_nets(ip_field, port_field, vals)
end

if not ip then
buffer_append(nets_buf, LOGICAL_OR, exp_port, i)
expression_append(nets_buf, LOGICAL_OR, exp_port, i)
goto continue
end

if not port then
buffer_append(nets_buf, LOGICAL_OR, exp_ip, i)
expression_append(nets_buf, LOGICAL_OR, exp_ip, i)
goto continue
end

buffer_append(nets_buf, LOGICAL_OR,
"(" .. exp_ip .. LOGICAL_AND .. exp_port .. ")", i)
expression_append(nets_buf, LOGICAL_OR,
"(" .. exp_ip .. LOGICAL_AND .. exp_port .. ")", i)

::continue::
end -- for
Expand Down Expand Up @@ -166,7 +166,7 @@ local function get_expression(route)
gen = "(net.protocol != \"https\"" .. LOGICAL_OR .. gen .. ")"
end

buffer_append(expr_buf, LOGICAL_AND, gen)
expression_append(expr_buf, LOGICAL_AND, gen)
end

-- stream expression
Expand All @@ -176,11 +176,11 @@ local function get_expression(route)
local dst_gen = gen_for_nets("net.dst.ip", "net.dst.port", dsts)

if src_gen then
buffer_append(expr_buf, LOGICAL_AND, src_gen)
expression_append(expr_buf, LOGICAL_AND, src_gen)
end

if dst_gen then
buffer_append(expr_buf, LOGICAL_AND, dst_gen)
expression_append(expr_buf, LOGICAL_AND, dst_gen)
end

if src_gen or dst_gen then
Expand All @@ -192,7 +192,7 @@ local function get_expression(route)

local gen = gen_for_field("http.method", OP_EQUAL, methods)
if gen then
buffer_append(expr_buf, LOGICAL_AND, gen)
expression_append(expr_buf, LOGICAL_AND, gen)
end

if not is_empty_field(hosts) then
Expand All @@ -218,11 +218,11 @@ local function get_expression(route)
exp = "(" .. exp .. LOGICAL_AND ..
"net.port ".. OP_EQUAL .. " " .. port .. ")"
end
buffer_append(hosts_buf, LOGICAL_OR, exp, i)
expression_append(hosts_buf, LOGICAL_OR, exp, i)
end -- for route.hosts

buffer_append(expr_buf, LOGICAL_AND,
hosts_buf:put(")"):get())
expression_append(expr_buf, LOGICAL_AND,
hosts_buf:put(")"):get())
end

gen = gen_for_field("http.path", function(path)
Expand All @@ -238,7 +238,7 @@ local function get_expression(route)
return p
end)
if gen then
buffer_append(expr_buf, LOGICAL_AND, gen)
expression_append(expr_buf, LOGICAL_AND, gen)
end

if not is_empty_field(headers) then
Expand All @@ -257,15 +257,15 @@ local function get_expression(route)
op = OP_REGEX
end

buffer_append(single_header_buf, LOGICAL_OR,
name .. " " .. op .. " " .. escape_str(value:lower()), i)
expression_append(single_header_buf, LOGICAL_OR,
name .. " " .. op .. " " .. escape_str(value:lower()), i)
end

buffer_append(headers_buf, LOGICAL_AND,
single_header_buf:put(")"):get())
expression_append(headers_buf, LOGICAL_AND,
single_header_buf:put(")"):get())
end

buffer_append(expr_buf, LOGICAL_AND, headers_buf:get())
expression_append(expr_buf, LOGICAL_AND, headers_buf:get())
end

return expr_buf:get()
Expand Down

1 comment on commit cbcddf2

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:cbcddf26cef02e1d3016701c4ba5cee8230e2260
Artifacts available https://github.com/Kong/kong/actions/runs/5711817347

Please sign in to comment.