使用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(...args: number[]):string
        decode(hashid:string):number[]
    }
 
    interface myHashidsConstructor {
        new: (this: void, saltKey: string,length?:number) => Hashids;
    }
    var id: myHashidsConstructor
    export = {
         ...id
    }
 
}
  • 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

posted on   荣锋亮  阅读(64)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用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

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示