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 2022/02/27 13:03:52 UTC

[GitHub] [apisix] YuanYingdong commented on a change in pull request #6459: chore: remove some dumplicated code in ops.lua

YuanYingdong commented on a change in pull request #6459:
URL: https://github.com/apache/apisix/pull/6459#discussion_r815436748



##########
File path: apisix/cli/ops.lua
##########
@@ -282,77 +282,51 @@ Please modify "admin_key" in conf/config.yaml .
 
     local ports_to_check = {}
 
+    local function validate_and_get_listen_addr(port_name, default_ip, configured_ip,
+                                                default_port, configured_port)
+        local ip = configured_ip or default_ip
+        local port = tonumber(configured_port) or default_port
+        if ports_to_check[port] ~= nil then
+            util.die(port_name .. " ", port, " conflicts with ", ports_to_check[port], "\n")
+        end
+        ports_to_check[port] = port_name
+        return ip .. ":" .. port
+    end
+
     -- listen in admin use a separate port, support specific IP, compatible with the original style
     local admin_server_addr
     if yaml_conf.apisix.enable_admin then
         if yaml_conf.apisix.admin_listen or yaml_conf.apisix.port_admin then
-            local ip = "0.0.0.0"
-            local port = yaml_conf.apisix.port_admin or 9180
-
             if yaml_conf.apisix.admin_listen then
-                ip = yaml_conf.apisix.admin_listen.ip or ip
-                port = tonumber(yaml_conf.apisix.admin_listen.port) or port
-            end
-
-            if ports_to_check[port] ~= nil then
-                util.die("admin port ", port, " conflicts with ", ports_to_check[port], "\n")
+                admin_server_addr = validate_and_get_listen_addr("admin port", "0.0.0.0",
+                                            yaml_conf.apisix.admin_listen.ip,
+                                            9180, yaml_conf.apisix.admin_listen.port)
+            else

Review comment:
       The old code indicates that `yaml_conf.apisix.admin_listen` and  `yaml_conf.apisix.port_admin` may be both `nil`, I think we need to keep the code cosistent.




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

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org