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-10-23 11:14:19 +08:00
|
|
|
|
local accountApi = require("api.system.account")
|
2025-09-27 15:19:58 +08:00
|
|
|
|
|
2025-10-16 16:47:24 +08:00
|
|
|
|
--定义相关路由,前端接口url地址
|
2025-09-27 15:14:13 +08:00
|
|
|
|
local routes = {
|
2025-10-23 11:14:19 +08:00
|
|
|
|
--用户相关路由接口
|
2025-10-15 10:35:42 +08:00
|
|
|
|
{
|
2025-10-23 20:25:17 +08:00
|
|
|
|
paths = { "/api/get-user" },
|
|
|
|
|
|
metadata = { "metadata get-user" },
|
2025-10-20 16:52:40 +08:00
|
|
|
|
methods = { "GET" },
|
2025-10-23 20:25:17 +08:00
|
|
|
|
handler = userApi.get_alluser,
|
2025-10-15 10:35:42 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-10-20 16:52:40 +08:00
|
|
|
|
paths = { "/api/get-user/:id" },
|
|
|
|
|
|
metadata = { "metadata /api/get-user/id" },
|
|
|
|
|
|
methods = { "GET" },
|
2025-10-16 16:47:24 +08:00
|
|
|
|
handler = userApi.get_user,
|
2025-10-15 10:35:42 +08:00
|
|
|
|
},
|
2025-10-20 16:52:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
paths = { "/api/delete-user/:id" },
|
|
|
|
|
|
metadata = { "metadata /api/delete-user/id" },
|
|
|
|
|
|
methods = { "DELETE" },
|
|
|
|
|
|
handler = userApi.delete_user,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
paths = { "/api/add-user" },
|
|
|
|
|
|
metadata = { "metadata /api/add-user" },
|
|
|
|
|
|
methods = { "POST" },
|
|
|
|
|
|
handler = userApi.add_user,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
paths = { "/api/update-user/:id" },
|
|
|
|
|
|
metadata = { "metadata /api/update-user/id" },
|
|
|
|
|
|
methods = { "PUT" },
|
|
|
|
|
|
handler = userApi.update_user,
|
|
|
|
|
|
},
|
2025-10-23 11:14:19 +08:00
|
|
|
|
--账户相关路由接口
|
|
|
|
|
|
{
|
2025-10-23 17:46:02 +08:00
|
|
|
|
paths = { "/api/get-accounts" },
|
|
|
|
|
|
metadata = { "metadata get-accounts" },
|
2025-10-23 11:14:19 +08:00
|
|
|
|
methods = { "GET" },
|
|
|
|
|
|
handler = accountApi.get_allaccounts,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
paths = { "/api/get-account/:id" },
|
|
|
|
|
|
metadata = { "metadata /api/get-account/id" },
|
|
|
|
|
|
methods = { "GET" },
|
|
|
|
|
|
handler = accountApi.get_account,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
paths = { "/api/delete-account/:id" },
|
|
|
|
|
|
metadata = { "metadata /api/delete-account/id" },
|
|
|
|
|
|
methods = { "DELETE" },
|
|
|
|
|
|
handler = accountApi.delete_account,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
paths = { "/api/add-account" },
|
|
|
|
|
|
metadata = { "metadata /api/add-account" },
|
|
|
|
|
|
methods = { "POST" },
|
|
|
|
|
|
handler = accountApi.add_account,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
paths = { "/api/update-account/:id" },
|
|
|
|
|
|
metadata = { "metadata /api/update-account/id" },
|
|
|
|
|
|
methods = { "PUT" },
|
|
|
|
|
|
handler = accountApi.update_account,
|
|
|
|
|
|
},
|
2025-09-27 15:14:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-16 16:47:24 +08:00
|
|
|
|
-- 初始化路由
|
2025-10-15 17:22:04 +08:00
|
|
|
|
local rx, err = radix.new(routes)
|
|
|
|
|
|
if not rx then
|
|
|
|
|
|
ngx.say("Not Found")
|
2025-10-16 16:47:24 +08:00
|
|
|
|
ngx.exit(ngx.HTTP_NOT_FOUND)
|
2025-09-27 15:14:13 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
2025-10-16 16:47:24 +08:00
|
|
|
|
--获取访问的uri地址
|
2025-10-15 17:22:04 +08:00
|
|
|
|
local uri = ngx.var.uri
|
|
|
|
|
|
local opts = {
|
|
|
|
|
|
method = ngx.var.request_method,
|
|
|
|
|
|
matched = {}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-16 16:47:24 +08:00
|
|
|
|
-- 进行路由匹配和相关函数调用
|
2025-10-15 17:22:04 +08:00
|
|
|
|
local ok = rx:dispatch(uri, opts, opts.matched)
|
|
|
|
|
|
if not ok then
|
|
|
|
|
|
ngx.say("Not Found")
|
2025-10-16 16:47:24 +08:00
|
|
|
|
ngx.exit(ngx.HTTP_NOT_FOUND)
|
|
|
|
|
|
end
|