From d2faad4f45fee0654ae63d1020b16356ac6873e2 Mon Sep 17 00:00:00 2001 From: chronolaw Date: Thu, 29 Feb 2024 07:38:32 +0800 Subject: [PATCH] refactor(router/atc): simplify searching for field accessor function --- kong/router/fields.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kong/router/fields.lua b/kong/router/fields.lua index 126bbce671fd..4294e84b7603 100644 --- a/kong/router/fields.lua +++ b/kong/router/fields.lua @@ -199,6 +199,11 @@ end -- is_http -- stream subsystem needs not to generate func local function get_field_accessor(funcs, field) + local f = FIELDS_FUNCS[field] + if f then + return f + end + error("unknown router matching schema field: " .. field) end @@ -259,7 +264,7 @@ if is_http then get_field_accessor = function(funcs, field) - local f = funcs[field] + local f = FIELDS_FUNCS[field] or funcs[field] if f then return f end @@ -447,8 +452,7 @@ end function _M:get_value(field, params, ctx) - local func = FIELDS_FUNCS[field] or - get_field_accessor(self.funcs, field) + local func = get_field_accessor(self.funcs, field) return func(params, ctx) end