add file exists checking in my_uuid

This commit is contained in:
2023-11-12 02:25:29 +08:00
parent 0b4cc166e0
commit b4835ef305
5 changed files with 28 additions and 77 deletions
+15 -6
View File
@@ -1,14 +1,23 @@
local commons = require("lib.commons")
local _M = {}
function _M.uuid()
local uuid_cmd = "/usr/bin/uuid"
local handle = io.popen(uuid_cmd)
local result = handle:read("*a")
local r2 = string.gsub(result, "%s+", "")
local r3 = string.gsub(r2,"\n","")
ngx.log(ngx.INFO, "uuid -> ", r3)
return r3
if commons.file_exists(uuid_cmd) then
local handle = io.popen(uuid_cmd)
local result = handle:read("*a")
local r2 = string.gsub(result, "%s+", "")
local r3 = string.gsub(r2,"\n","")
ngx.log(ngx.INFO, "uuid -> ", r3)
return r3
else
ngx.status = 500
ngx.log(ngx.ERR, "my_uuid *FAILED* `/usr/bin/uuid` not exists!")
ngx.say("my_uuid *FAILED* `/usr/bin/uuid` not exists!")
ngx.exit()
end
end
return _M