属性
lor:
version
router
route
request
response
fn
app
create_app
Router
Route
Request
Response 属性
lor() 或者 App:
cache
settings --conf函数操作此table设置key --value
router
run(final_handler) /---步骤一---/
init(options)
default_configuration(options)
handle(req, res, callback) /---步骤二 ---*/
use(path, fn) --跳转执行 inner_use(, path, fn) --> (Router:new({})):use('/', fn, ) /**步骤一 **/
erroruse(path, fn)
inner_use(fn_args_length, path, fn)
init_method()--初始化 给自身新增更多的方法
get = true, -- work well
post = true, -- work well
head = true, -- no test
options = true, -- no test
put = true, -- work well
patch = true, -- no test
delete = true, -- work well
trace = true, -- no test
all = true -- todo:
all(path, fn)
conf(setting, val) --设置配置
getconf(setting) --获取配置
enable(setting)--将某项配置开启
disable(setting)--将某项配置关闭 属性
Router:
new(options) /**步骤二 **/
name => 值为 "origin-router-" .. random()
group_router
stack -- 将把实例化后的Layer对象插入到此table中 /**步骤五 **/
_call()
call()
handle(req, res, out) /---步骤三 ---*/
use(path, fn, fn_args_length) -- 新增路由 /**步骤三 **/
app_route(path) -- 新增路由
route(path) -- 新增路由
init() --初始化 给自身新增更多的方法
get = true, -- work well
post = true, -- work well
head = true, -- no test
options = true, -- no test
put = true, -- work well
patch = true, -- no test
delete = true, -- work well
trace = true, -- no test
all = true -- todo: 属性
Layer:
new(path, options, fn, fn_args_length) /**步骤四 **/
handle => 值为 fn
name => 值为 "layer-" .. random()
params
path => 值为 path
keys
length => 值为 fn_args_length
is_end => 值为 false
is_start => 值为 true
pattern => 值为 "/"
handle_error(err, req, res, next)
handle_request(req, res, next)
match(path) --对每一个路由规则 进行匹配 属性
Request
next
new()
path = ngx.var.uri, -- uri
method = ngx.req.get_method(),
query = ngx.req.get_uri_args(),
params = {},
body = body,
body_raw = ngx.req.get_body_data(),
url = ngx.var.request_uri,
origin_uri = ngx.var.request_uri,
uri = ngx.var.request_uri,
headers = headers, -- request headers
req_args = ngx.var.args,
found = false -- or not
is_found()
set_found(found) 属性
Response
http_status = nil,
headers = {},
locals = {},
body = '--default body. you should not see this by default--',
view = nil
render(view_file, data)
html(data)
redirect(url, code, query)
location(url, data)
send(text) main.lua
路线一:
app --> lor() --执行那个 “函数A” --> Application.lua文件的返回 返回新table 并将Application类设为新table的元方法
注意:Application 下有如下方法
get = true, -- work well
post = true, -- work well
head = true, -- no test
options = true, -- no test
put = true, -- work well
patch = true, -- no test
delete = true, -- work well
trace = true, -- no test
all = true -- todo:
值等于同一个函数 function(path, fn)
local route = router:app_route(path)
route[http_method](route, fn) -- like route:get(fn)
return self
end --> lor.lua文件的返回 传入 一个“函数A“进去
--> wrap.lua文件的返回 返回新table 并将wrap类设为新table的元方法 路线二:
app:use(函数)--> App:use() 没有返回值 --> App:inner_use() 返回self
--> Router:use() 返回self 并设置了 table.insert(self.stack, layer:new())
--> Layer:new() 返回新table 并将 Layer类设为新table的元方法 路线三:
app:run() --> App:run() --> App:handle()-->router:handle //作者在此函数下了不少功夫.,.....
05-03 21:20