2025-10-22 08:46:41 +08:00
|
|
|
|
---
|
|
|
|
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
|
|
|
|
--- Created by admin.
|
|
|
|
|
|
--- DateTime: 2025/10/15 09:12
|
|
|
|
|
|
---
|
|
|
|
|
|
local snowflake = require("util.snowflake")
|
|
|
|
|
|
|
|
|
|
|
|
local workerId = 0 -- 假设当前机器的ID是1,范围在[0, 31]之间
|
|
|
|
|
|
local datacenterId = 0 -- 数据中心ID,范围在[0, 31]之间
|
|
|
|
|
|
local snow = snowflake.new(workerId, datacenterId)
|
|
|
|
|
|
local id = snow:generateUniqueId()-- 生成ID
|
|
|
|
|
|
ngx.say("Generated ID:"..snow.int64_to_string(id))
|
|
|
|
|
|
|
2025-10-22 14:35:41 +08:00
|
|
|
|
--max =a and b or c--a?b:c
|
|
|
|
|
|
|
|
|
|
|
|
--去掉组装最后一位逗号(,)
|
|
|
|
|
|
--local newKeys = keys:sub(1, #keys -1)
|
|
|
|
|
|
--local newValues = values:sub(1, #values -1)
|
|
|
|
|
|
|
2025-10-22 08:46:41 +08:00
|
|
|
|
--读取请求体的数据
|
|
|
|
|
|
--ngx.req.read_body()
|
|
|
|
|
|
|
|
|
|
|
|
--获取请求数据
|
|
|
|
|
|
--local body_data = ngx.req.get_body_data()
|
|
|
|
|
|
|
|
|
|
|
|
--if not body_data then
|
|
|
|
|
|
-- ngx.say("read file error:", err)
|
|
|
|
|
|
-- return ngx.exit(400)
|
|
|
|
|
|
--end
|
|
|
|
|
|
--local len = #body_data
|
|
|
|
|
|
|
|
|
|
|
|
--local file_name = ngx.req.get_body_file()
|
|
|
|
|
|
--ngx.say("file length:", len)
|
|
|
|
|
|
|
|
|
|
|
|
--ngx.req.read_body_in_buffer(ngx.var.request_body_file)
|
|
|
|
|
|
|
|
|
|
|
|
--ngx.say(body_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--local cjson = require("cjson")
|
|
|
|
|
|
--local file_path = "/home/frankly/work/test.dat"
|
|
|
|
|
|
--local file_length = 1024 * 1024 * 400
|
|
|
|
|
|
--local f, err = io.input(file_path, "r")
|
|
|
|
|
|
--if not f then
|
|
|
|
|
|
-- ngx.say("read file error:"..err)
|
|
|
|
|
|
-- return
|
|
|
|
|
|
--end
|
|
|
|
|
|
--local content = f:read(file_length) --读取文件内容
|
|
|
|
|
|
--f:close() --关闭文件
|
|
|
|
|
|
----ngx.say(content)
|
|
|
|
|
|
--local res = {
|
|
|
|
|
|
-- key = "data",
|
|
|
|
|
|
-- value = content
|
|
|
|
|
|
--}
|
|
|
|
|
|
----ngx.header["Length"] = #content
|
|
|
|
|
|
--ngx.header["Content-Type"] = 'application/json; charset=UTF-8'
|
|
|
|
|
|
--ngx.say(cjson.encode(res))
|
2025-10-17 15:43:19 +08:00
|
|
|
|
--ngx.log(ngx.INFO, "send data success")
|