Skip to content

Commit

Permalink
refactor: folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Aug 1, 2023
1 parent 1e819b5 commit 1a17c5a
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Add this to `Cargo.toml`

```toml
[dependencies]
salvo = { version= "*" }
salvo = { version= "0.49" }
tokio = { version = "1", features = ["macros"] }
```

Expand Down
2 changes: 1 addition & 1 deletion README.zh-hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ cargo new hello_salvo --bin

```toml
[dependencies]
salvo = { version= "*" }
salvo = { version= "0.49" }
tokio = { version = "1", features = ["macros"] }
```
`main.rs` 中创建一个简单的函数句柄, 命名为`hello`, 这个函数只是简单地打印文本 `"Hello World"`.
Expand Down
2 changes: 1 addition & 1 deletion README.zh-hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ cargo new hello_salvo --bin

```toml
[dependencies]
salvo = { version= "*" }
salvo = { version= "0.49" }
tokio = { version = "1", features = ["macros"] }
```
`main.rs` 中創建一個簡單的函數句柄, 命名為`hello`, 這個函數隻是簡單地打印文本 `"Hello World"`.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions crates/core/src/routing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Routing and filters
//! Router can route http requests to different handlers.

pub mod filter;
pub mod filters;
mod router;
pub use filter::*;
pub use filters::*;
pub use router::{DetectMatched, Router};

use std::borrow::Cow;
Expand Down
42 changes: 21 additions & 21 deletions crates/core/src/routing/router.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{self, Formatter};
use std::sync::Arc;

use super::filter;
use super::filters;
use super::{Filter, FnFilter, PathFilter, PathState};
use crate::handler::{Handler, WhenHoop};
use crate::http::uri::Scheme;
Expand Down Expand Up @@ -302,82 +302,82 @@ impl Router {

/// Add a [`SchemeFilter`] to current router.
///
/// [`SchemeFilter`]: super::filter::HostFilter
/// [`SchemeFilter`]: super::filters::HostFilter
#[inline]
pub fn scheme(self, scheme: Scheme) -> Self {
self.filter(filter::scheme(scheme))
self.filter(filters::scheme(scheme))
}

/// Add a [`HostFilter`] to current router.
///
/// [`HostFilter`]: super::filter::HostFilter
/// [`HostFilter`]: super::filters::HostFilter
#[inline]
pub fn host(self, host: impl Into<String>) -> Self {
self.filter(filter::host(host))
self.filter(filters::host(host))
}

/// Add a [`PortFilter`] to current router.
///
/// [`PortFilter`]: super::filter::PortFilter
/// [`PortFilter`]: super::filters::PortFilter
#[inline]
pub fn port(self, port: u16) -> Self {
self.filter(filter::port(port))
self.filter(filters::port(port))
}

/// Create a new child router with [`MethodFilter`] to filter get method and set this child router's handler.
///
/// [`MethodFilter`]: super::filter::MethodFilter
/// [`MethodFilter`]: super::filters::MethodFilter
#[inline]
pub fn get<H: Handler>(self, handler: H) -> Self {
self.push(Router::with_filter(filter::get()).handle(handler))
self.push(Router::with_filter(filters::get()).handle(handler))
}

/// Create a new child router with [`MethodFilter`] to filter post method and set this child router's handler.
///
/// [`MethodFilter`]: super::filter::MethodFilter
/// [`MethodFilter`]: super::filters::MethodFilter
#[inline]
pub fn post<H: Handler>(self, handler: H) -> Self {
self.push(Router::with_filter(filter::post()).handle(handler))
self.push(Router::with_filter(filters::post()).handle(handler))
}

/// Create a new child router with [`MethodFilter`] to filter put method and set this child router's handler.
///
/// [`MethodFilter`]: super::filter::MethodFilter
/// [`MethodFilter`]: super::filters::MethodFilter
#[inline]
pub fn put<H: Handler>(self, handler: H) -> Self {
self.push(Router::with_filter(filter::put()).handle(handler))
self.push(Router::with_filter(filters::put()).handle(handler))
}

/// Create a new child router with [`MethodFilter`] to filter delete method and set this child router's handler.
///
/// [`MethodFilter`]: super::filter::MethodFilter
/// [`MethodFilter`]: super::filters::MethodFilter
#[inline]
pub fn delete<H: Handler>(self, handler: H) -> Self {
self.push(Router::with_filter(filter::delete()).handle(handler))
self.push(Router::with_filter(filters::delete()).handle(handler))
}

/// Create a new child router with [`MethodFilter`] to filter patch method and set this child router's handler.
///
/// [`MethodFilter`]: super::filter::MethodFilter
/// [`MethodFilter`]: super::filters::MethodFilter
#[inline]
pub fn patch<H: Handler>(self, handler: H) -> Self {
self.push(Router::with_filter(filter::patch()).handle(handler))
self.push(Router::with_filter(filters::patch()).handle(handler))
}

/// Create a new child router with [`MethodFilter`] to filter head method and set this child router's handler.
///
/// [`MethodFilter`]: super::filter::MethodFilter
/// [`MethodFilter`]: super::filters::MethodFilter
#[inline]
pub fn head<H: Handler>(self, handler: H) -> Self {
self.push(Router::with_filter(filter::head()).handle(handler))
self.push(Router::with_filter(filters::head()).handle(handler))
}

/// Create a new child router with [`MethodFilter`] to filter options method and set this child router's handler.
///
/// [`MethodFilter`]: super::filter::MethodFilter
/// [`MethodFilter`]: super::filters::MethodFilter
#[inline]
pub fn options<H: Handler>(self, handler: H) -> Self {
self.push(Router::with_filter(filter::options()).handle(handler))
self.push(Router::with_filter(filters::options()).handle(handler))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use openapi::*;
pub mod endpoint;
pub use endpoint::{Endpoint, EndpointArgRegister, EndpointOutRegister, EndpointRegistry};
pub mod extract;
mod router;
mod routing;

cfg_feature! {
#![feature ="swagger-ui"]
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi/src/openapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub mod server;
mod tag;
mod xml;

use crate::{router::NormNode, Endpoint};
use crate::{routing::NormNode, Endpoint};

static PATH_PARAMETER_NAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\{([^}:]+)").unwrap());

Expand Down
File renamed without changes.

0 comments on commit 1a17c5a

Please sign in to comment.