-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugs.woo
More file actions
69 lines (54 loc) · 1.8 KB
/
plugs.woo
File metadata and controls
69 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- plugs core lib
local class_plugs = {}
-- lib_name [example:oshine.bitmap]
function class_plugs:new (lib_name)
assert(lib_name, 'lib name empty')
if not self._http then
self._http = require('http')
--print(self._http:new())
end
self._lib_name = lib_name
local conf=require('oshine.cwm.conf.conf')
local current_dir = conf.install_dir .. str_replace(lib_name, '.', '/')
print('want load lib:==', current_dir)
self.plugs_yml = yml_parse(current_dir .. '/package.yml')
print("plugs port:", self.plugs_yml.port)
-- when init plugs,check plugs if is running
self._port = self.plugs_yml.port
self._plugs = require(lib_name .. '.init')
self._plugs.run(self.plugs_yml, current_dir)
local res, error_message = self._http.request("GET", 'http://127.0.0.1:' .. self._port .. '/ping', {})
if error_message then
print(error_message)
else
print(res['status_code'])
print('Plugs ping reply:==', res.body)
end
return self
end
function class_plugs:load (lib_name)
-- load another plugs
return self:new(lib_name)
end
function class_plugs:call (...)
-- use http request to call plugs function
local result, error_message = self._http.request("POST", 'http://127.0.0.1:' .. self._port .. '/call', {
body = json_encode({ ... }),
headers = { op = 123 }
})
if error_message then
return nil, 'Call plugs func got err:' .. error_message
else
if result['status_code'] == 200 then
local res = json_decode(result.body)
if res.code == 0 then
return res.data
else
return res.data, res.msg
end
else
return nil, 'Plugs return status not 200'
end
end
end
return class_plugs