From e43555997194bd4a6581b62793dae16a30eb1afe Mon Sep 17 00:00:00 2001 From: chronolaw Date: Fri, 14 Jun 2024 11:30:15 +0800 Subject: [PATCH] style(pdk): get hostname with `string.strip` --- kong/pdk/node.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kong/pdk/node.lua b/kong/pdk/node.lua index 9302c17cde1a..d622d10dc281 100644 --- a/kong/pdk/node.lua +++ b/kong/pdk/node.lua @@ -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" @@ -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