zoukankan      html  css  js  c++  java
  • 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(3, path, fn)  -->  (Router:new({})):use('/', fn, 3)  /**步骤一 **/
         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 -- 404 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 //作者在此函数下了不少功夫.,.....
      
  • 相关阅读:
    hihoCoder#1128 二分·二分查找
    hihoCoder#1127 二分图三·二分图最小点覆盖和最大独立集
    hihoCoder#1122 二分图二•二分图最大匹配之匈牙利算法
    hihoCoder#1105 题外话·堆
    Ajax详细剖析
    web框架之--Tornado
    web框架之--先来个介绍
    前端之--Jquery-玩穿它!
    前端之--DOM详解应用
    前端之--JavaScript作用域--超细讲解
  • 原文地址:https://www.cnblogs.com/sixiong/p/5968901.html
Copyright © 2011-2022 走看看