<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 插件使用 終于有時間更新插件使用相關的文章了,這里首先給大家介紹一個**內容替換模塊**中使用的手機號脫敏插件 # 插件編寫 1. 先看這個手機號脫敏插件的源代碼 ``` local sub = string.sub local gsub = ngx.re.gsub local gmatch = ngx.re.gmatch local re = "(13[0-9]|14[5,7]|15[0-3,5-9]|17[0,3,5-8]|18[0-9]|166|198|199|147)\\d{8}" local TB = {} local tag = false local function Teltoasterisk(_tel) -- 中間 4 位 return sub(_tel,1,4).."****"..sub(_tel,9) end local function insert_Tb(Stel) if not TB[Stel] then TB[Stel] = Teltoasterisk(Stel) end end local function Telgmatch(tel_str) local it, err = gmatch(tel_str, re, "jo") if not it then return end while true do local m,err = it() if err then return end if not m then return end tag = true insert_Tb(m[0]) end end local _M = { _VERSION = "0.01" } local function tel_ast(str_all , _tb_args) Telgmatch(str_all) if tag then for k,v in pairs(TB) do str_all = gsub(str_all,k,v) end end return str_all end _M.tel_ast = tel_ast return _M ``` 代碼編寫的非常好理解,當然了還有寫法不規范的地方,如果說您可以調用C代碼編寫的模塊,其工作的效率應該是最高的。(希望有寫好C模塊的同學可以分享一下so文件或者源代碼) 2. 性能測試測試 用于性能測試的代碼如下 ``` local optl = require("optl") local str = [=[xxxxx]=] local re = "(13[0-9]|14[5,7]|15[0-3,5-9]|17[0,3,5-8]|18[0-9]|166|198|199|147)\\d{8}" local TB = {} local tag = false local function Teltoasterisk(_tel) -- 中間 4 位 return string.sub(_tel,1,4).."****"..string.sub(_tel,9) end local function insert_Tb(Stel) if not TB[Stel] then TB[Stel] = Teltoasterisk(Stel) end end local function Telgmatch(tel_str) local it, err = ngx.re.gmatch(tel_str, re, "jo") if not it then return end while true do local m,err = it() if err then return end if not m then return end tag = true insert_Tb(m[0]) end end local function Telngxfind(tel_str) local f,t = ngx.re.find(tel_str,re,"jo") if f then tag = true local tmptel = string.sub(tel_str,f,t) insert_Tb(string.sub(tel_str,f,t)) local tmp_str = string.sub(tel_str,t) Telngxfind(tmp_str) end end local function Telmatch(tel_str) local m,e = ngx.re.match(tel_str,re) if m then tag = true insert_Tb(m[0]) local f,t = string.find(tel_str,m[0],1,true) local tmp_str = string.sub(tel_str, t) Telmatch(tmp_str) end end local startTime = os.clock() local num = tonumber(optl.get_paramByName("num")) or 10000 local fuc = optl.get_paramByName("fuc") local T_fuc = {} T_fuc.ngxfind = Telngxfind T_fuc.match = Telmatch T_fuc.gmatch = Telgmatch f = T_fuc[fuc] or Telngxfind for i=1,num do f(str) end if tag then for k,v in pairs(TB) do str = ngx.re.gsub(str,k,v) end end local msg = string.format(">> This function cost: %.4f ms", os.clock()-startTime) optl.sayHtml_ext({code="ok",msg=msg,len=#str,tb=TB,tag=tag}) ``` 為了和真實的環境接近,找了一篇最佳實踐的頁面,在內容里面添加了一些手機號碼,其分布跨度也是比較大的。 該頁面內容字符串長度:70964 ![](https://i.vgy.me/mxhVnu.png) 大家也可以對比一下,使用這個 ngx.re.gmatch 效率最高,當然了如果有C模塊的更好了。 完整代碼 分享在[百度網盤 ](https://pan.baidu.com/s/1zIiRhw2zTAA5AMcc6XbF-A) # replace_Mod --- 插件編寫 閱讀到這里就想著怎么編寫一個自己的插件,那就接著往下看吧。 先看一個最簡單的 內容替換插件 ``` local _M = { _VERSION = "0.01" } local function replace_hello(str_all , _tb_args) -- 這里可以使用函數完成你想要的替換結果 return ngx.re.gsub(str_all, "hello", "HELLO") end _M.replace_hello = replace_hello return _M ``` 首先需要返回一個table,讓后給這個 table 添加一個方法。 其次這個方法需要接收 2 個參數 str_all :這個是需要替換的內容(也就是 整個 Response ,該內容是 openstar 獲取傳遞過來的) _tb_args:調用參數(使得插件的使用更加靈活,ps 傳遞的就是一個 table ,這里不需要序列化的,減少性能的損耗) 接下來就是編寫你想要的邏輯和內容了,這里和普通編寫lua腳本的一樣的,可以調用其他人的lua模塊,還有調用c代碼等等...,當然不要把自己堵塞了!!!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看