membphis commented on a change in pull request #1930:
URL: https://github.com/apache/incubator-apisix/pull/1930#discussion_r462676463



##########
File path: apisix/utils/table-util.lua
##########
@@ -0,0 +1,58 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local type = type
+local core = require("apisix.core")
+local table = core.utils.table
+local utils = core.utils
+
+local _M = {}
+
+
+local function patch(node_value, sub_path, conf)
+    local sub_value = node_value
+    local sub_paths = utils.split_uri(sub_path)
+    for i = 1, #sub_paths - 1 do
+      local sub_name = sub_paths[i]

Review comment:
       bad indentation, 8 spaces required.

##########
File path: apisix/admin/global_rules.lua
##########
@@ -18,6 +18,7 @@ local core = require("apisix.core")
 local schema_plugin = require("apisix.admin.plugins").check_schema
 local type = type
 local tostring = tostring
+local table_util = require("apisix.utils.table-util")

Review comment:
       Some do not understand, why do we need to create a new utils.table-util 
file? And this name makes me a little confused, not sure what it is for.

##########
File path: apisix/admin/services.lua
##########
@@ -209,7 +209,7 @@ function _M.patch(id, conf, sub_path)
     local node_value = res_old.body.node.value
 
     if sub_path and sub_path ~= "" then
-        local code, err, node_val = table_util.patch(node_value, sub_path, 
conf);
+        local code, err, node_val = core.table.patch(node_value, sub_path, 
conf);

Review comment:
       `;` is useless, we need to remove it

##########
File path: apisix/admin/services.lua
##########
@@ -21,7 +21,7 @@ local upstreams = require("apisix.admin.upstreams")
 local tostring = tostring
 local ipairs = ipairs
 local type = type
-local table_util = require("apisix.utils.table-util")
+

Review comment:
       two blank lines are enough.

##########
File path: apisix/admin/upstreams.lua
##########
@@ -243,7 +242,7 @@ function _M.patch(id, conf, sub_path)
     local new_value = res_old.body.node.value
 
     if sub_path and sub_path ~= "" then
-        local code, err, node_val = table_util.patch(new_value, sub_path, 
conf);
+        local code, err, node_val = core.table.patch(new_value, sub_path, 
conf);

Review comment:
       ditto

##########
File path: apisix/core/table.lua
##########
@@ -105,4 +106,43 @@ local function merge(origin, extend)
 end
 _M.merge = merge
 
+
+local function split_uri(uri)
+    return ngx_re.split(uri, "/")
+end
+
+
+local function patch(node_value, sub_path, conf)
+    local sub_value = node_value
+    local sub_paths = split_uri(sub_path)

Review comment:
       we can call `ngx_re.split` directly

##########
File path: apisix/core/table.lua
##########
@@ -105,4 +106,43 @@ local function merge(origin, extend)
 end
 _M.merge = merge
 
+
+local function split_uri(uri)
+    return ngx_re.split(uri, "/")
+end
+
+
+local function patch(node_value, sub_path, conf)
+    local sub_value = node_value
+    local sub_paths = split_uri(sub_path)

Review comment:
       then we can remove function `split_uri`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to