日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Openresty编写Lua代码一例

發(fā)布時(shí)間:2023/12/13 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Openresty编写Lua代码一例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.前段時(shí)間糾結(jié)了很久,一直弄不清lua和tomcat的聯(lián)系。一直認(rèn)為是lua調(diào)用tomcat的接口才可使用,后面才明白過(guò)來(lái),進(jìn)入了一個(gè)誤區(qū),lua本身就是一門(mén)獨(dú)立的腳本語(yǔ)言。在openresty里面配置好,即可編寫(xiě)映射和響應(yīng)。

下面是自己編寫(xiě)的lua代碼一例,僅供參考。還有些不完善,要開(kāi)始忙項(xiàng)目了,等有空再繼續(xù)更新。

2.下面是lua代碼,記得在nginx.conf寫(xiě)好配置。

local request_method = ngx.var.request_method local cjson = require("cjson") local mysql = require("resty.mysql") local quote = ngx.quote_sql_str local db,err = mysql:new() local function close_db(db) if not db then return end db:close() end if not db thennax.say("new mysql error",err) endlocal args = nil local username = nil local pwd = nil if "GET" == request_method thenargs = ngx.req.get_uri_args() elseif "POST" == ngx.request_method thenngx.req.read_body()args = ngx.req.get_post_args() end username = tostring(args["username"]) pwd = tostring(args["pwd"]) if username == nil thenngx.say("username not nil")return elseif username == '' thenngx.say("username not nil")return elseif pwd == nil thenngx.say("password not nil")return; elseif pwd == '' thenngx.say("password not nil")return; enddb:set_timeout(1000) local props = { host = "127.0.0.1", port = 3306, database = "hwc_hello", user = "root", password = "hwc123456" } local res, err, errno, sqlstate = db:connect(props) if not res then ngx.say("connect to mysql error : ", err, " , errno : ", errno, " , sqlstate : ", sqlstate) return close_db(db) end local select_name = "select username from user_table where username="..quote(username) res, err, errno, sqlstate = db:query(select_name) if not res then ngx.exec("/vi/404.html") return close_db(db) end local result = {} result.success = true; result.info = "登錄成功" ngx.say(cjson.encode(result))

?

轉(zhuǎn)載于:https://www.cnblogs.com/dslx/p/9208622.html

總結(jié)

以上是生活随笔為你收集整理的Openresty编写Lua代码一例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。