未提供项目描述
项目描述
通过HTTP服务器和简单的API在远程中心运行函数。这极大地促进了在JSON应用程序的节点之间进行通信和共享工作负载。
安装
pip install pop-gate
获取功能
网关扩展了pop-tree,可以用来获取所有可用资源的详细信息
gate --refs "gate.init.tree"
curl http://localhost:5000 -H "Content-Type: application/json" -d '{"ref": "gate.init.tree"}'
用法
从命令行运行网关服务器并公开特定的中心引用模式。‘–refs’代表允许列表上的中心模式。‘–prefix’告诉网关假定所有引用都位于特定的动态命名空间下。
在这个例子中,我们将使用前缀“gate”并允许在‘hub.gate.init’下的所有引用
gate --prefix gate --refs "init.*"
使用curl在远程服务器上运行如下
curl http://localhost:8080 -H "Content-Type: application/json" -d '{"ref": "init.test"}'
可以通过向调用添加额外的键来传递关键字参数
curl http://localhost:8080 -H "Content-Type: application/json" -d '{"ref": "init.test", "args": ["arg1", "arg2"], "kwargs": {"kwarg1": "value1"}}'
测试
使用测试库本地安装网关
git clone git@gitlab.com:saltstack/pop/gate.git
pip install -e gate -r requirements-test.txt
使用pytest运行测试
pytest gate/tests
集成
为了在自己的项目中使用网关,请像这样将网关配置添加到您的conf.py中
my_project/conf.py
CLI_CONFIG = {
# Gate options
"host": {"source": "gate"},
"port": {"source": "gate"},
"server": {"source": "gate"},
"matcher": {"source": "gate"},
"prefix": {"source": "gate"},
"refs": {"source": "gate", "default": ["gate.init.test"]},
}
将网关启动代码添加到项目的初始化器中,如下所示
my_project/my_project/init.py
def __init__(hub):
# Horizontally merge the gate dynamic namespace into your project
hub.pop.sub.add(dyne_name="gate")
def cli(hub):
# Load the config from gate onto hub.OPT
hub.pop.config.load(["my_project", "gate"], cli="my_project")
# Create the asyncio loop
hub.pop.loop.create()
# Get the default gate server, and other options from hub.OPT.gate
gate_server = hub.OPT.gate.server
# Create the server coroutine
coro = hub.gate.init.start(gate_server=gate_server)
# Start the gate server
hub.pop.Loop.run_until_complete(coro)
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分发
pop-gate-6.0.2.tar.gz (11.8 kB 查看哈希值)
构建分发
pop_gate-6.0.2-py3-none-any.whl (14.5 kB 查看哈希值)
关闭
pop-gate-6.0.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4ccdfcabf6727fdfbc942dc7f38e59644ec7c81f40fd8bba6c341c928a58b9e9 |
|
MD5 | fb06be1a3db775b12885198b8654eb0d |
|
BLAKE2b-256 | 480919a0edd0dde6c6726c8bec5ce85dfbba446339d7ab90fb05a1b406fb12ad |
关闭
pop_gate-6.0.2-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 97b99d6b10829942c1ef21bd2f6f993365c80a5e082c929f43aaa2bf30c19d68 |
|
MD5 | ada51896675037ad89ae17615bb5ea58 |
|
BLAKE2b-256 | 1b6fb40f509a36f3ee377b9a7da32169077ecbe173ab2d1253149e5533dd58be |