diff --git a/lib/oleg.moon b/lib/oleg.moon new file mode 100644 index 0000000..703c1fe --- /dev/null +++ b/lib/oleg.moon @@ -0,0 +1,30 @@ +config = require("lapis.config").get! +http = require "lapis.nginx.http" + +request = (method, table, key, value=nil) -> + oleg_res, code = http.simple { + url: "http://#{config.oleg.host}:#{config.oleg.port}/#{table}/#{key}" + method: method + body: value + } + + if code ~= 200 + return nil, code + + if not oleg_res + return nil, 404 + + oleg_res, nil + +ret = {} + +ret.get = (table, key) -> + request "GET", table, key + +ret.delete = (table, key) -> + request "DELETE" + +ret.set = (table, key, value) -> + request "POST", table, key, value + +ret