使用TypeScriptToLua+openresty-lua-types+docker-compose nginx hashids 集成使用
以前我简单说明过hashids 的类型定义,以下是集成使用## 环境准备
详细介绍可以参考 https://www.cnblogs.com/rongfengliang/p/16210941.html
集成hashids
- dockerfile 安装hashid
使用luarocks
FROM openresty/openresty:1.21.4.1rc3-1-alpine-fat
RUN /usr/local/openresty/luajit/bin/luarocks install hashids
代码集成
- 添加类型定义
hashids.d.ts
declare module "hashids" {
interface Hashids {
encode(
decode(hashid:string):number[]
}
interface myHashidsConstructor {
new: (this: void, saltKey: string,length?:number) => Hashids;
}
var id: myHashidsConstructor
export = {
}
}
- ts 配置调整
"compilerOptions": {
"outDir": "./lua_code",
"types": ["openresty-lua-types"],
"lib": ["esnext","DOM"],
"module":"commonjs",
"target": "esnext",
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
"esModuleInterop": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"strict": true
},
- 代码集成
还是以前的添加了hashids 生成的
indexpage.ts
import myid = require("hashids")
let hashids = myid.new("dalongdemo",15)
ngx.say(hashids.encode(100,200,200))
运行
- docker build
docker-compose build
- 编译效果
- 构建
yarn dev
- 启动
docker-compose up -d
- 效果
参考资料
https://luarocks.org/modules/leihog/hashids
https://www.cnblogs.com/rongfengliang/p/16210941.html
https://github.com/rongfengliang/typescript-to-lua-openresty-lua-types-docker-compose
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2019-04-30 几个方便的基于es 的开源文档索引系统
2019-04-30 使用状态文件+vigil 监控系统状态
2019-04-30 zeebe 集成elasticsearch exporter && 添加operate
2019-04-30 Distributed PostgreSQL on a Google Spanner Architecture – Storage Layer
2019-04-30 Distributed PostgreSQL on a Google Spanner Architecture – Query Layer
2019-04-30 alicemq 方便的RabbitMQ 可视化工具
2018-04-30 ambassador kubernetes native api gateway