AuthPlatform/src/api/system/role.lua

82 lines
2.0 KiB
Lua
Raw Normal View History

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/9/25 08:19
---
--解析url路由过滤库
local radix = require("resty.radixtree")
--数据表业务处理
local systemRole = require("service.system.role")
--定义相关路由前端接口url地址
local routes = {
--角色相关路由接口
{
paths = { "/yum/v1/system/roles" },
methods = { "GET" },
filter_fun = function(vars)
ngx.ctx.perms = "system::roles::list"
return true
end,
handler = systemRole.getSystemRoles,
},
{
paths = { "/yum/v1/system/roles/:id" },
methods = { "GET" },
filter_fun = function(vars)
ngx.ctx.perms = "system::roles::view"
return true
end,
handler = systemRole.getSystemRole,
},
{
paths = { "/yum/v1/system/roles" },
methods = { "POST" },
filter_fun = function(vars)
ngx.ctx.perms = "system::roles::add"
return true
end,
handler = systemRole.addSystemRole,
},
{
paths = { "/yum/v1/system/roles/:id" },
methods = { "DELETE" },
filter_fun = function(vars)
ngx.ctx.perms = "system::roles::delete"
return true
end,
handler = systemRole.deleteSystemRole,
},
{
paths = { "/yum/v1/system/roles/:id" },
methods = { "PUT" },
filter_fun = function(vars)
ngx.ctx.perms = "system::roles::edit"
return true
end,
handler = systemRole.updateSystemRole,
},
}
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--获取访问的uri地址
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.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end