lor框架代码分析
- 属性
- 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 //作者在此函数下了不少功夫.,.....
lor框架代码分析的更多相关文章
- 一个简单的"RPC框架"代码分析
0,服务接口定义---Echo.java /* * 定义了服务器提供的服务类型 */ public interface Echo { public String echo(String string) ...
- PHPCMS V9 框架代码分析(入口程序)
PHPCMS是采用MVC设计模式开发,基于模块和操作的方式进行访问,采用单一入口模式进行项目部署和访问,无论访问任何一个模块或者功能,只有一个统一的入口. 入口程序是在前期处理用户请求的引导程序.它是 ...
- Linux摄像头驱动学习之:(六)UVC-基本框架代码分析
仿照内核的自带UVC(usb video class)驱动程序写的一版简化驱动,仅供学习,实际项目开发中应该尽量使用内核自带的驱动,除非内核自带的驱动不支持此款硬件才需要自己写驱动. 下面就直接上代码 ...
- 开源代码分析之Android/iOS Hybrid JSBridge框架
Hybrid开发是现在的主流形式,对于业务快速迭代的公司尤其重要.曾将在鞋厂接触了很多关于Hybrid的理念,在这里分享一些Hybrid框架思想. Hybrid框架包括Native与H5的通信,Web ...
- 11.5 Android显示系统框架_Vsync机制_代码分析
5.5 surfaceflinger对vsync的处理buffer状态图画得不错:http://ju.outofmemory.cn/entry/146313 android设备可能连有多个显示器,AP ...
- 完整全面的Java资源库(包括构建、操作、代码分析、编译器、数据库、社区等等)
构建 这里搜集了用来构建应用程序的工具. Apache Maven:Maven使用声明进行构建并进行依赖管理,偏向于使用约定而不是配置进行构建.Maven优于Apache Ant.后者采用了一种过程化 ...
- 动态加载框架DL分析
动态加载框架DL分析 插件化开发,主要解决三个问题1.动态加载未安装的apk,dex,jar等文件2.activity生命周期的问题,还有service3.Android的资源调用的问题 简单说一下怎 ...
- angular代码分析之异常日志设计
angular代码分析之异常日志设计 错误异常是面向对象开发中的记录提示程序执行问题的一种重要机制,在程序执行发生问题的条件下,异常会在中断程序执行,同时会沿着代码的执行路径一步一步的向上抛出异常,最 ...
- Linux内核中的GPIO系统之(3):pin controller driver代码分析
一.前言 对于一个嵌入式软件工程师,我们的软件模块经常和硬件打交道,pin control subsystem也不例外,被它驱动的硬件叫做pin controller(一般ARM soc的datash ...
随机推荐
- sql 内联,左联,右联,全联
联合查询效率较高,以下例子来说明联合查询(内联.左联.右联.全联)的好处: T1表结构(用户名,密码) userid (int) username varchar(20) password varc ...
- jenkins 入门教程(上)【转】
转自:https://www.cnblogs.com/yjmyzz/p/jenkins-tutorial-part-1.html jenkins是一个广泛用于持续构建的可视化web工具,持续构建说得更 ...
- Django Xadmin - 重构django admin
一.Django admin的执行流程 https://www.cnblogs.com/weihengblog/p/9122509.html 我的博客,介绍了django admin执行流程 二.Xa ...
- vue实现结算淘宝购物车效果
实现单选时的价格,全选时价格 单选效果图 全选效果图 html <template> <!-- 淘宝结算购物车 --> <div class="settleme ...
- dedecms调用文章列表第一篇和下面几篇不同的方法
{dede:arclist row=1 orderby=pubdate infolen=60 limit=0,1} <li class="dot1"><img s ...
- mysqlsla 安装
tar -zxvf mysqlsla-2.03.tar.gz cd mysqlsla-2.03 perl Makefile.PLmake && make install BEGIN f ...
- MFC+WinPcap编写一个嗅探器之四(获取模块)
这一节主要介绍如何获取设备列表,比较简单 获取设备列表主要是在CAdpDlg中完成,也就是对应之前创建的选择适配器模块,如图: 当打开选择适配器对话框后,在列表视图控件中显示当前主机所有适配器及适配器 ...
- [水煮 ASP.NET Web API2 方法论](1-4)从 MVC Controller 链接到 API Controller 以及反向链接
问题 想创建一个从 ASP.NET MVC controller 到 ASP.NET Web API controller 的直接链接,或者反向链接. 解决方案 可以使用 System.Web.Htt ...
- BZOJ 1861: [Zjoi2006]Book 书架 (splay)
1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 1453 Solved: 822[Submit][Stat ...
- hdu 5936 2016ccpc 杭州 - D
数学题好难啊!!!! 最长长度不超过十位, 折半枚举... 题解 #include<bits/stdc++.h> #define LL long long #define fi first ...