MoonScript调用LUA-CJSON

作者:糖果

Lapis的util库有对cjson封装,而我们想更直接的调用CJSON的方法,而不想依赖的封装。

我们首先实现一个MoonScript写文件的代码:

写文件:


write_data = (var, rule)->
    path = "/home/xxx"  
    file = io.open(path,"aw")
    if file==nil then
        return

    ret = file\write(rule)
    file\close()
    return(t)

访问接口:

    restyhttp = require "resty.http"
    httpc = restyhttp.new()
    res, err = httpc\request_uri("http://0.0.0.0/getjson")
    jsonbody = ""
    if res.status == ngx.HTTP_OK 
      jsonbody = res.body
    else 
      jsonbody = nil 

对JSON数据DECODE:

    write_data(0, jsonbody)
    t = json.decode(jsonbody)
    tjson = json.decode(t['message'])
    ngx.say(util.serialise_value(tjson))
    ""

糖果

糖果
LUA从入门到放弃

服务器大负载情况下客户端出现Connection reset by peer

服务器大负载情况下客户端出现Connection reset by peer Continue reading

Nginx+Lua中文WIKI

Published on March 14, 2019

F5收购Nginx

Published on March 12, 2019