Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(pdk): get hostname with string.strip #13208

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions kong/pdk/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@

local ffi = require "ffi"
local private_node = require "kong.pdk.private.node"
local tools_string = require("kong.tools.string")
local uuid = require("kong.tools.uuid").uuid
local bytes_to_str = require("kong.tools.string").bytes_to_str


local floor = math.floor
local lower = string.lower
local match = string.match
local gsub = string.gsub
local sort = table.sort
local insert = table.insert
local strip = tools_string.strip
local bytes_to_str = tools_string.bytes_to_str
local ngx = ngx
local shared = ngx.shared
local C = ffi.C
local ffi_new = ffi.new
local ffi_str = ffi.string


local NODE_ID_KEY = "kong:node_id"


Expand Down Expand Up @@ -254,13 +256,13 @@ local function new(self)

if res == 0 then
local hostname = ffi_str(buf, SIZE)
return gsub(hostname, "%z+$", "")
return strip(hostname)
end

local f = io.popen("/bin/hostname")
local hostname = f:read("*a") or ""
f:close()
return gsub(hostname, "\n$", "")
return strip(hostname)
end


Expand Down
Loading