conf参数是插件的相关配置信息ctx参数缓存请求相关的数据信息
ngx内置变量即为openresty中的ngx全局变量
| 变量路径 | 变量说明 |
|---|---|
| ngx.req | 所有请求中变量都可使用 |
| ngx.resp | 所有请求response变量都可以使用 |
插件把函数注册到apisix插件引擎,默认会给插件提供conf、ctx等参数对象
| 变量路径 | 变量协议 |
|---|---|
| conf.{schema} | 通过conf.定义schema获取数据 |
local var = ctx.var
| 变量路径 | 变量说明 |
|---|---|
| var.schem | 请求协议 |
| var.host | 请求host |
| var.server_port | 请求端口 |
| var.upstream_uri | upstream uri |
- 自定义缓存数据各阶段传递
function _M.rewrite(conf,ctx)
ctx.metadata = { name = "plugin" }
end
function _M.access(conf,ctx)
if ctx.metadata == "plugin" then
return 403, "plugin name not validate"
end
end
local user = "jxa"
local s, e = core.string.find(user, "jx")
schema 插件文件定义的schema
local ok, err = core.schema.check(schema, conf)
日志级别: info,warn,error
core.log.warn(")
local schema = core.json.encode(conf)