国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Lua腳本本地調(diào)試

這篇具有很好參考價(jià)值的文章主要介紹了Lua腳本本地調(diào)試。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

這里主要使用日志的方式進(jìn)行debug

環(huán)境依賴

項(xiàng)目對(duì)openresty包的依賴比較高,所以環(huán)境基礎(chǔ)都在openresty下進(jìn)行

openresty的使用

openresty下載地址

下載完成后解壓,具體使用方式和nginx沒有什么區(qū)別,主要依賴文件是一下幾個(gè)

nginx.exe # 負(fù)責(zé)啟動(dòng)服務(wù)
conf/nginx.conf  # nginx的配置文件 使用lua腳本主要也是在這里配置
logs  # 日志查看 排錯(cuò)

lua鏈接mysql校驗(yàn)用戶

這里拿lua鏈接mysql為例

 -- utils_mysql
 local mysql = require "resty.mysql"
local cjson = require "cjson"
local _M = {}

local function getUser(userNo, orgCode)
    db = _M:new()
    if not db then
        return false, {}

    end
    local userRes, err, errcode, sqlstate = db:query(
        "SELECT COUNT(F_user_account) F_count FROM t_user WHERE F_user_account = " .. userNo .. " AND F_deleted='0'")
    -- 目前用戶不存在放行  只存入相關(guān)信息 設(shè)置匿名用戶
    if not userRes then
        ngx.log(ngx.ERR, "用戶--" .. userNo .. "-- 不存在" .. err)
        return false, {
            status = 401,
            message = "Bad token; " .. tostring(err)
        }
    end
    local orgUserRes, err, errcode, sqlstate = db:query(
        "SELECT COUNT(F_user_account) F_count, F_status FROM t_org_user WHERE F_user_account = " .. userNo .. " AND F_org_code = " ..
            orgCode .. " AND F_deleted='0'")
    if not orgUserRes then
        ngx.log(ngx.ERR, "用戶--" .. userNo .. "--和--" .. orgCode .. "--組織關(guān)系不存在"..err)
        return false, {
            status = 4060,
            message = "用戶需要登錄"
        }
    end


    ngx.log(ngx.ERR, "orgUserRes Is" .. cjson.encode(orgUserRes))

    -- lua腳本似乎不遵循index=0的原則 [{"F_count":"1","F_status":"0"}]
    if orgUserRes[1]["F_status"] ~= '0' then
        ngx.log(ngx.ERR, "該組織下角色已被禁用,請(qǐng)聯(lián)系管理員".. err)
        return false, {
            status = 7025,
            message = "該組織下角色已被禁用,請(qǐng)聯(lián)系管理員"
        }
    end
    ngx.log(ngx.WARN, "UserRes Is "..cjson.encode(userRes).. "orgUserRes Is" .. cjson.encode(orgUserRes))
    -- 校驗(yàn)成功的返回信息
    ngx.say('CheckUser Success')
    return true, {}
end

function _M.new(self)
    local db, err = mysql:new()
    if not db then
        ngx.log(ngx.ERR, "failed to instantiate mysql: ", err)
        return nil
    end
    -- 1 sec
    db:set_timeout(1000)
    local ok, err, errcode, sqlstate = db:connect{
        host = "xxxx",
        port = "xxxx",
        database = "xxxx",
        user = "xxxx",
        password = "xxxx"
    }
    if not ok then
        ngx.log(ngx.ERR, "failed to connect:  ", err, errcode, sqlstate)
        return nil
    end
    return db
end

function _M.close(self)
    local sock = self.sock
    if not sock then
        return nil, "not initialized"
    end
    if self.subscribed then
        return nil, "subscribed state"
    end
    -- put it into the connection pool of size 100,
    -- with 10 seconds max idle timeout
    local ok, err = self.sock:set_keepalive(10000, 100)
    if not ok then
        ngx.log(ngx.ERR, "failed to set keepalive:", err)
        return
    end
end

getUser('username', 'org_code')
-- return _M

修改配置文件nginx.conf


#user  nobody;
worker_processes 1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
events {
    worker_connections 1024;
}


http {
    include mime.types;
    default_type application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
    sendfile on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout 65;

    #gzip  on;

    server {
        # 修改原本的80端口為8765
        listen 8765;
        server_name localhost;

        #charset koi8-r;

        # 添加的lua腳本校驗(yàn)路徑
        location /testlua {
            default_type 'text/html';  # 默認(rèn)文本方式返回
            charset utf-8;
            lua_code_cache off;  # 不使用緩存
            content_by_lua_file  luaScript/utils_mysql.lua;  # 需要執(zhí)行的lua腳本文件路徑,這里的路徑是相對(duì)于壓縮包的路徑,也可以使用絕對(duì)路徑 注意windows下 \ 需要變成 /
        }

        #access_log  logs/host.access.log  main;
        location / {
            root html;
            index index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}


啟動(dòng)openresty

雙擊 nginx.exe即可,瀏覽器輸入http://localhost:8765進(jìn)入啟動(dòng)頁面

調(diào)試過程中,每次點(diǎn)擊nginx.exe都會(huì)啟動(dòng)新的線程,導(dǎo)致有時(shí)候更新的項(xiàng)目但是打到的請(qǐng)求還是在老的配置服務(wù)上,為確保每次請(qǐng)求都是最新的,最好把線程都刪掉

windows
# 展示線程
tasklist /fi "imagename eq nginx.exe"
# 殺掉線程
taskkill /fi "imagename eq nginx.exe" -f

Lua腳本本地調(diào)試,Gateway,lua,junit,android,gateway

Lua腳本校驗(yàn)

瀏覽器輸入http://localhost:8765/testlua進(jìn)入插件校驗(yàn)頁面

運(yùn)行的日志和錯(cuò)誤信息都可以在logs/access.log&error.log中找到,由于這里已經(jīng)是處理完成的腳本信息,如何解決問題這里不做展示。

需要注意的是,在腳本文件中ngx.log(ngx.ERR, "xxxx")最好都設(shè)置成err級(jí)別,別的級(jí)別好像不會(huì)展示在日志中

Lua腳本本地調(diào)試,Gateway,lua,junit,android,gateway

校驗(yàn)

Error

Lua腳本本地調(diào)試,Gateway,lua,junit,android,gateway

Success

日志和錯(cuò)誤信息都可以在logs/access.log&error.log中找到,由于這里已經(jīng)是處理完成的腳本信息,如何解決問題這里不做展示。

需要注意的是,在腳本文件中ngx.log(ngx.ERR, "xxxx")最好都設(shè)置成err級(jí)別,別的級(jí)別好像不會(huì)展示在日志中

[外鏈圖片轉(zhuǎn)存中…(img-PpfLXDLJ-1689328661208)]

校驗(yàn)

Error

[外鏈圖片轉(zhuǎn)存中…(img-j6J54ZsA-1689328661209)]

Success

Lua腳本本地調(diào)試,Gateway,lua,junit,android,gateway文章來源地址http://www.zghlxwxcb.cn/news/detail-596869.html

到了這里,關(guān)于Lua腳本本地調(diào)試的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • lua腳本獲取table類型-Java使用lua腳本操作redis獲取zset元素的集合

    lua腳本獲取table類型-Java使用lua腳本操作redis獲取zset元素的集合 7.0點(diǎn)贊功能-定時(shí)持久化到數(shù)據(jù)庫-lua腳本的編寫_嗶哩嗶哩_bilibili https://www.bilibili.com/video/BV1bu411j75u 這個(gè)腳本主要是放到Springboot工程里的, 這里如果是向放到字段控制臺(tái)執(zhí)行,那就要加入 eval 以及其他參數(shù):

    2024年02月13日
    瀏覽(17)
  • 無涯教程-Lua - 調(diào)試語句

    Lua提供了一個(gè)調(diào)試庫,該庫提供了所有原始函數(shù)供無涯教程創(chuàng)建自己的調(diào)試器。即使沒有內(nèi)置的Lua調(diào)試器,也有許多針對(duì)Lua的調(diào)試器,這些調(diào)試器由各種開發(fā)人員創(chuàng)建,其中許多開源。 下表列出了Lua調(diào)試庫中可用的函數(shù)及其用法。 Sr.No. Method Purpose 1 debug() 進(jìn)入交互式模式進(jìn)行

    2024年02月14日
    瀏覽(22)
  • 【實(shí)戰(zhàn)】使用Lua腳本怎么清理redis中的數(shù)據(jù)【實(shí)戰(zhàn)】使用Lua腳本怎么清理redis中的數(shù)據(jù)

    首先我們通過hiredis 向redis 中寫入了數(shù)據(jù),這里我們主要以測(cè)試為目的,所以,Key 值設(shè)定為毫秒級(jí)時(shí)間戳。 但是當(dāng)我們測(cè)試完成之后,需要驗(yàn)證實(shí)際情況,這里我們直接使用redis-cli 登錄數(shù)據(jù)庫看看。 本次測(cè)試完成,接下來要結(jié)合業(yè)務(wù)開始測(cè)試,需要清理數(shù)據(jù)庫,但是一條一

    2024年02月13日
    瀏覽(20)
  • Redis之Lua腳本

    Redis之Lua腳本

    目錄 Lua腳本 編寫Lua腳本 ?springboot整合redis使用lua Lua腳本 ? ? ? ?Redis在2.6推出了腳本功能,允許開發(fā)者使用Lua語言編寫腳本傳到Redis中執(zhí)行。使用腳本的好處如下: 1. 減少網(wǎng)絡(luò)開銷:本來5次網(wǎng)絡(luò)請(qǐng)求的操作,可以用一個(gè)請(qǐng)求完成,原先5次請(qǐng)求的邏輯放在redis服務(wù)器上完成。使

    2024年01月23日
    瀏覽(21)
  • Redis入門 - Lua腳本

    原文首更地址,閱讀效果更佳! Redis入門 - Lua腳本 | CoderMast編程桅桿 https://www.codermast.com/database/redis/redis-scription.html Redis 腳本使用 Lua 解釋器來執(zhí)行腳本。 Redis 2.6 版本通過內(nèi)嵌支持 Lua 環(huán)境。執(zhí)行腳本的常用命令為 EVAL。 Eval 命令的基本語法如下: EVAL script numkeys key [key ...]

    2024年02月09日
    瀏覽(27)
  • Lua腳本語言

    Lua腳本語言

    Lua(發(fā)音為\\\"loo-ah\\\",葡萄牙語中的\\\"lua\\\"意為月亮)是一種輕量級(jí)的、高效的、可嵌入的腳本編程語言。官網(wǎng)Lua最初由巴西計(jì)算機(jī)科學(xué)家Roberto Ierusalimschy、Waldemar Celes和Luiz Henrique de Figueiredo于1993年開發(fā),它的設(shè)計(jì)目標(biāo)是提供一種簡(jiǎn)單的、易擴(kuò)展的腳本語言,特別適用于嵌入到其他

    2024年02月07日
    瀏覽(23)
  • Lua腳本編程基礎(chǔ)

    一. 數(shù)據(jù)類型 ①基本類型 1. nil類型 2. boolean類型 3. numbers類型 4. string類型 ②高級(jí)類型 1. table類型 2. function類型 3. userdata類型 4. thread類型 ?二 . 腳本示例 三. lua與c/c++的互操作

    2024年02月12日
    瀏覽(16)
  • 一文學(xué)會(huì)lua腳本

    一文學(xué)會(huì)lua腳本

    Lua是一門簡(jiǎn)潔、高效的腳本語言,用于嵌入應(yīng)用程序和擴(kuò)展。我整理了一篇學(xué)習(xí)入門指南。希望對(duì)大家有所幫助。 Lua是一種小巧而強(qiáng)大的腳本語言,最初由巴西里約熱內(nèi)盧天主教大學(xué)的研究小組于1993年開發(fā)而成。Lua的設(shè)計(jì)目標(biāo)是為應(yīng)用程序提供靈活的擴(kuò)展和定制功能。它由

    2024年02月11日
    瀏覽(15)
  • 使用lua腳本操作redis

    使用lua腳本操作redis

    redis中實(shí)現(xiàn)事務(wù)有兩種方法: 1.WATCH監(jiān)視鍵的變動(dòng),然后MULTI開始事務(wù),EXEC提交事務(wù) WATCH key [key…]:監(jiān)視一個(gè)或多個(gè)鍵,如果在事務(wù)執(zhí)行之前被修改,則事務(wù)被打斷。 MULTI:標(biāo)記一個(gè)事務(wù)的開始。 EXEC:執(zhí)行事務(wù)中的所有命令。 DISCARD:取消一個(gè)事務(wù),放棄執(zhí)行事務(wù)中的所有命

    2024年02月16日
    瀏覽(15)
  • ardupilot開發(fā) --- Lua腳本篇

    ardupilot開發(fā) --- Lua腳本篇

    ArduPilot引入了對(duì)Lua腳本的支持; 可以同時(shí)運(yùn)行多個(gè)腳本; Lua腳本存放在 SD card 中; Copter-4.0 及以上版本才支持Lua腳本; scripting API ?scripting applets ? 飛控條件:2 MB of flash and 70 kB of memory ; 將Lua腳本上傳到 SD card’s APM/scripts 文件夾中,在Mission Planner使用MAVFTP可以上傳文件;

    2024年02月11日
    瀏覽(16)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包