You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/01/06 14:39:10 UTC

[GitHub] [apisix] membphis commented on a change in pull request #2965: feat: use luasocket instead of curl in etcd.lua

membphis commented on a change in pull request #2965:
URL: https://github.com/apache/apisix/pull/2965#discussion_r552671455



##########
File path: apisix/cli/etcd.lua
##########
@@ -195,31 +210,44 @@ function _M.init(env, show_output)
 
             local key =  (etcd_conf.prefix or "") .. dir_name .. "/"
 
-            local uri = host .. "/v3/kv/put"
+            local put_url = host .. "/v3/kv/put"
             local post_json = '{"value":"' .. base64_encode("init_dir")
                               .. '", "key":"' .. base64_encode(key) .. '"}'
-            local cmd = "curl " .. uri .. token_head .. " -X POST -d '" .. post_json
-                        .. "' --connect-timeout " .. timeout
-                        .. " --max-time " .. timeout * 2 .. " --retry 1 2>&1"
-
-            local res = util.execute_cmd(cmd)
-            if res:find("404 page not found", 1, true) then
-                util.die("gRPC gateway is not enabled in your etcd cluster, ",
-                         "which is required by Apache APISIX.", "\n")
+            local response_body = {}
+            local headers = {["Content-Length"] = #post_json}
+            if auth_token then
+                headers["Authorization"] = auth_token
+            end
+
+            local res, err = http.request{url = put_url, method = "POST",

Review comment:
       style: I prefer `http.request({...})`, it is easy to read




----------------------------------------------------------------
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:
users@infra.apache.org