<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Iron面向中間件的 Web 框架

          聯(lián)合創(chuàng)作 · 2023-09-20 08:45

          Iron ,一個用 Rust 編寫的可擴展的、并發(fā)的 Web 框架。

          Iron 是一個快速、靈活的面向中間件的服務(wù)器框架,它提供了小巧但健壯的基礎(chǔ)以創(chuàng)建復(fù)雜的應(yīng)用和 RESTful APIs。Iron 沒有和中間件捆綁在一起,任何東西都是可以拖拽的(drag-and-drop),這允許你天馬行空地進(jìn)行模塊設(shè)置。

          extern crate iron;
          extern crate time;
          use iron::prelude::*;
          use iron::{BeforeMiddleware, AfterMiddleware, typemap};
          use time::precise_time_ns;
          struct ResponseTime;
          impl typemap::Key for ResponseTime { type Value = u64; }
          impl BeforeMiddleware for ResponseTime {
              fn before(&self, req: &mut Request) -> IronResult<()> {
                  req.extensions.insert::<ResponseTime>(precise_time_ns());
                  Ok(())
              }
          }
          impl AfterMiddleware for ResponseTime {
              fn after(&self, req: &mut Request, res: Response) -> IronResult<Response> {
                  let delta = precise_time_ns() - *req.extensions.get::<ResponseTime>().unwrap();
                  println!("Request took: {} ms", (delta as f64) / 1000000.0);
                  Ok(res)
              }
          }
          fn hello_world(_: &mut Request) -> IronResult<Response> {
              Ok(Response::with((iron::status::Ok, "Hello World")))
          }
          fn main() {
              let mut chain = Chain::new(hello_world);
              chain.link_before(ResponseTime);
              chain.link_after(ResponseTime);
              Iron::new(chain).http("localhost:3000").unwrap();
          }
          瀏覽 12
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  蜜桃羞羞无码久久久 | 亚卅毛片 | 台湾佬大香蕉 | 欧美骚逼网| 操B无码|