Yiyiyimu commented on a change in pull request #2036:
URL: https://github.com/apache/apisix/pull/2036#discussion_r487992864



##########
File path: apisix/core/etcd.lua
##########
@@ -44,24 +49,144 @@ end
 _M.new = new
 
 
+local function kvs_to_node(kvs)
+    local node = {}
+    node.key = kvs.key
+    node.value = kvs.value
+    node.createdIndex = tonumber(kvs.create_revision)
+    node.modifiedIndex = tonumber(kvs.mod_revision)
+    return node
+end
+
+local function kvs_to_nodes(res, start_index)
+    res.body.node.dir = true
+    res.body.node.nodes = {}
+    for i=start_index, #res.body.kvs do
+        if start_index == 1 then
+            res.body.node.nodes[i] = kvs_to_node(res.body.kvs[i])
+        else
+            res.body.node.nodes[i-1] = kvs_to_node(res.body.kvs[i])

Review comment:
       Actually we are iterating through `i`, not `start_index`. Assume 
`start_index = 1`, nodes[1] would be kvs[1], and nodes[2] = kvs[2].
   
   BTW, `start_index` is to choose whether the first node of kvs should be 
included in nodes, `1` means include and `2` means not.




----------------------------------------------------------------
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