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 00:53:24 UTC

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

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

 ##########
 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:
   We better close the file handle before exiting the function. `file:close()`

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