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 2020/03/03 06:46:38 UTC

[GitHub] [incubator-apisix] moonming commented on a change in pull request #1182: Fix bad code style.

moonming commented on a change in pull request #1182: Fix bad code style.
URL: https://github.com/apache/incubator-apisix/pull/1182#discussion_r386825526
 
 

 ##########
 File path: bin/apisix
 ##########
 @@ -540,24 +540,22 @@ local function check_or_version(cur_ver_s, need_ver_s)
     return true
 end
 
+local function system_dns_resolver(file_path)
+    local file, err = io.open(file_path, "rb")
+    if not file then
+        return false, "failed to open file: " .. file_path .. ", error info:" .. err
+    end
 
-local function system_dns_resolver()
-    local file, err = io.open("/etc/resolv.conf")
-    if err then
-        return nil, err
-    else
-        local dns_addrs = {}
-        for line in file:lines() do
-            local addr, n = line:gsub("^nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$", "%1")
-            if n == 1 then
-                table.insert(dns_addrs, addr)
-            end
+    local dns_addrs = {}
+    for line in file:lines() do
+        local addr, n = line:gsub("^nameserver%s+(%d+%.%d+%.%d+%.%d+)%s*$", "%1")
+        if n == 1 then
+            table.insert(dns_addrs, addr)
         end
-        return dns_addrs
     end
+    return dns_addrs
 
 Review comment:
   the old codes not close file too.
   @membphis Do we have test cases to cover `bin/apisix`? only `apisix start/stop` looks not good enough.

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


With regards,
Apache Git Services