Commit 89aa8f62 authored by 周尚's avatar 周尚

optimize _BASE.db_read()

parent 00c25850
local _BASE = {}
local json = require ('cjson')
function _BASE.print_log(fname, ...)
local f = io.open(string.format("/Users/zhoush/openresty/nginx/logs/%s_%s.log", fname, os.date("%Y%m%d")), "a+")
local str = ""
......@@ -15,21 +15,20 @@ function _BASE.print_log(fname, ...)
f:close()
end
function _BASE.db_read()
local f = io.open("/Users/zhoush/openresty/nginx/conf/dbs.json", "r")
function _BASE.db_read(dbpath)
local f = io.open("/Users/zhoush/openresty/nginx/conf/"..dbpath, "r")
local tmp = f:read("a*")
local db_st = json.decode(tmp)
f:close()
return db_st
end
function _BASE.close_db(db)
if not db then
return
end
local ok, err = db:close()
local ok, err = db:close()
if not ok then
print_log("failed to close:", err)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment