haproxy-api-rs 通过rust 开发haproxy lua 扩展

haproxy-api-rs 是利用了mlua 可以很好的集成lua 到rust 中,这样我们就能使用rust 开发高效的lua 扩展了

参考玩法

  • 配置模块

默认使用的是库模式,与以前的load_lua 会有一些差异

global
    master-worker
    # MacOS 注意应该使用cpath 模式
    lua-prepend-path "../../target/debug/lib?.dylib" cpath
    lua-prepend-path "target/release/lib?.so" cpath
    lua-load haproxy.lua

haproxy.lua

实际上就是直接加载rust 暴露的模块

require("haproxy_simple_module")

说明

haproxy-api-rs 目前支持haproxy 2.8 + 对于喜欢使用rust 同时希望lua 代码不直接暴露的很值得尝试下

参考资料

https://www.arpalert.org/src/haproxy-lua-api/3.2/index.html

https://github.com/khvzak/haproxy-api-rs

https://github.com/mlua-rs/mlua

posted on 2025-05-31 08:00  荣锋亮  阅读(45)  评论(0)    收藏  举报

导航