Back to search
1.1.0
README1.1.0
lualoader
use lua to handle simple http requests
安装
- Use Lip.
lip install github.com/sapidexs/lualoader.
编译
Linux amd64
- 确保正确clone了submodule。进入lua目录并执行make。
cd lua && make && cd ..。 - 执行
CGO_ENABLED=1 go build .。
Windows amd64
- 下载
mingw-w64编译套件,并添加至环境变量。 - 下载dlfcn-win32项目并编译,将
libdl.a放入/path/to/mingw-w64/lib/下,将src/dlfcn.h放入/path/to/mingw-w64/include/下。 - 从lua官网下载页下载lua并编译(
mingw32-make.exe mingw),将src/下除Makefilelua.exeluac.exe外所有文件放入本项目lua/文件夹下。 - 设置
CGO_ENABLED=1。 - 执行
go build .。
Linux amd64 (Debian 12.6) 交叉编译至 RISC-V 64 (MilkV-Duo)
- 详见
riscv64-build.md。
运行
- 直接运行生成的
lualoader可执行文件即可。
配置
config.json为配置文件,首次启动时会自动生成。port为服务端口,默认:19130。
日志
errlog.txt文件为错误日志,会记录运行错误。
关于Lua
- 使用cgo绑定原版lua(5.4)
插件系统
- 插件位于
plugins目录下。每个插件有单独的目录。 - 目录下必须包含一个
manifest.json配置文件。示例内容如下。
{
"manifest_version": 2,
"name": "helloworld",
"entry": "main.lua",
"plugin_version": [
1,
0,
1
],
"author": [
"odorajbotoj"
],
"description": "hello, world!",
"platform": {
"os": [
"linux"
]
}
}
| 键名 | 含义 |
|---|---|
manifest_version | manifest标准标识符,无需修改 |
name | 插件名称 |
entry | 插件入口文件 |
plugin_version | 插件版本,遵循语义化版本规范,数字数组 |
author | 插件作者,字符串数组 |
description | 插件描述 |
platform | 插件所适配系统和架构。有os和arch两个字段,值均为字符串数组 |
-
插件必须包含一个
Enable函数与一个Disable函数,分别在启用和禁用时调用。这两个函数无参数,无返回值。 -
插件必须包含一个
HandlerTable表,用于注册路由。这个表以字符串为键,以函数为值。函数有一个参数,有一个返回值,均为表。 -
关于参数表的项:
| 键名 | 含义 |
|---|---|
method | string,请求方法 |
proto | string,请求协议 |
body | string,请求体 |
host | string,请求目标地址 |
remoteAddr | string,请求源地址 |
requestURI | string,请求的URI |
header | string-string table嵌套string table,请求头 |
form | string-string table嵌套string table,请求附带表单 |
postPorm | string-string table嵌套string table,请求附带Post表单 |
trailer | string-string table嵌套string table,请求额外信息 |
urlQuery | string-string table嵌套string table,请求URL参数 |
- 关于返回值表的项:
| 键名 | 含义 |
|---|---|
status | number,响应码 |
body | string,响应体 |
header | string-string table嵌套string table,响应头 |