You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
local ngx = ngx
local core = require("apisix.core")
local schema = {
type = "object",
properties = {
key = { type = "string" },
}
}
local plugin_name = "testetcd"
local _M = {
version = 0.1,
priority = 70,
name = plugin_name,
schema = schema,
}
function _M.check_schema(conf, schema_type)
return core.schema.check(schema, conf)
end
function _M.init()
end
function _M.destroy()
end
function _M.rewrite(conf, ctx)
end
function _M.access(conf, ctx)
local key = conf["key"]
local etcd_cli, prefix, err = core.etcd.new()
if not etcd_cli then
core.log.warn("create etcd_cli failed, error --- > " , err)
return
end
-- in etcd v2, get could implicitly turn into readdir
-- while in v3, we need to do it explicitly
local res, err = etcd_cli:readdir(key)
if not res then
core.log.warn("read etcd value failed, key --- > " , key)
return
end
core.log.warn(core.json.encode(res.body))
end
function _M.body_filter(conf, ctx)
end
function _M.delayed_body_filter(conf, ctx)
end
return _M
然后在路由中配置该插件
作用就是访问该路由 ,会在日志中打印etcd中 key为 /testetcd 的value值,
先用命令行 etcdctl put /testetcd hahahah赋值
然后访问 打印出如下信息
使用etcdctl get /testetcd 可以获取到
Environment
APISIX version:2.15.0
The text was updated successfully, but these errors were encountered:
Description
我写了个测试插件 testetcd.lua
然后在路由中配置该插件

作用就是访问该路由 ,会在日志中打印etcd中 key为 /testetcd 的value值,
先用命令行 etcdctl put /testetcd hahahah赋值
然后访问 打印出如下信息

使用etcdctl get /testetcd 可以获取到

Environment
The text was updated successfully, but these errors were encountered: