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/11/08 00:40:12 UTC
[GitHub] [apisix] tokers commented on a diff in pull request #8270: feat: add method that parse ip from /etc/hosts in high priority
tokers commented on code in PR #8270:
URL: https://github.com/apache/apisix/pull/8270#discussion_r1016031580
##########
apisix/core/resolver.lua:
##########
@@ -19,15 +19,67 @@
--
-- @module core.resolver
-local json = require("apisix.core.json")
-local log = require("apisix.core.log")
-local utils = require("apisix.core.utils")
+local json = require("apisix.core.json")
+local log = require("apisix.core.log")
+local utils = require("apisix.core.utils")
+local string_match = string.match
+local open = io.open
+
+
+local DEFAULT_HOSTS = "/etc/hosts"
+local HOSTS_IP_MATCH_CACHE = {}
local _M = {}
+local function guess_name_type(name)
+ if name:match("^[%d%.]+$") then
+ return "ipv4"
+ end
+
+ if name:find(":") then
+ return "ipv6"
+ end
+
+ return "hostname"
+end
+
+
+local function init_hosts_ip()
+ if not DEFAULT_HOSTS then
+ return
+ end
+
+ local file = open(DEFAULT_HOSTS)
+ if not file then
+ return
Review Comment:
It's better to print the error reason here.
--
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