2025-09-27 15:14:13 +08:00
|
|
|
---
|
|
|
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
|
|
|
--- Created by admin.
|
2025-09-27 15:19:58 +08:00
|
|
|
--- DateTime: 2025/9/24 15:29
|
2025-09-27 15:14:13 +08:00
|
|
|
---
|
2025-10-15 10:35:42 +08:00
|
|
|
local radix = require("resty.radixtree")
|
2025-10-15 17:22:04 +08:00
|
|
|
local userApi = require("api.system.user")
|
2025-09-27 15:19:58 +08:00
|
|
|
|
2025-09-27 15:14:13 +08:00
|
|
|
local routes = {
|
2025-10-15 10:35:42 +08:00
|
|
|
{
|
2025-10-15 17:22:04 +08:00
|
|
|
paths = { "/api/user" },
|
|
|
|
|
metadata = { "metadata /user" },
|
|
|
|
|
methods = { "GET", "POST" },
|
|
|
|
|
handler = userApi.get_allusers,
|
2025-10-15 10:35:42 +08:00
|
|
|
},
|
|
|
|
|
{
|
2025-10-15 17:22:04 +08:00
|
|
|
paths = { "/api/user/:id" },
|
|
|
|
|
metadata = { "metadata /user/id" },
|
|
|
|
|
methods = { "GET", "PUT", "DELETE" },
|
|
|
|
|
handler = userApi.get_users,
|
2025-10-15 10:35:42 +08:00
|
|
|
},
|
|
|
|
|
{
|
2025-10-15 17:22:04 +08:00
|
|
|
paths = { "/api/admin/:name", "/api/superuser/:name" },
|
2025-10-15 10:35:42 +08:00
|
|
|
metadata = { "metadata /admin/name" },
|
|
|
|
|
methods = { "GET", "POST", "PUT" },
|
|
|
|
|
filter_fun = function(vars, opts)
|
|
|
|
|
return vars["arg_access"] == "admin"
|
|
|
|
|
end
|
|
|
|
|
}
|
2025-09-27 15:14:13 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-15 17:22:04 +08:00
|
|
|
local rx, err = radix.new(routes)
|
|
|
|
|
if not rx then
|
|
|
|
|
ngx.say("-----")
|
|
|
|
|
ngx.status = 404
|
|
|
|
|
ngx.say("Not Found")
|
|
|
|
|
--ngx.exit()
|
2025-09-27 15:14:13 +08:00
|
|
|
end
|
|
|
|
|
|
2025-10-15 17:22:04 +08:00
|
|
|
local uri = ngx.var.uri
|
|
|
|
|
local opts = {
|
|
|
|
|
method = ngx.var.request_method,
|
|
|
|
|
matched = {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local ok = rx:dispatch(uri, opts, opts.matched)
|
|
|
|
|
if not ok then
|
|
|
|
|
ngx.status = 404
|
|
|
|
|
ngx.say("Not Found")
|
|
|
|
|
--ngx.exit()
|
|
|
|
|
end
|