Skip to content

Commit 20a5d4f

Browse files
Merge pull request #2 from hubertshelley/develop
路由已完成
2 parents ba792f3 + f51eeff commit 20a5d4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1165
-43
lines changed

.DS_Store

6 KB
Binary file not shown.

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ repos:
1111
- id: end-of-file-fixer
1212
- id: mixed-line-ending
1313
- id: trailing-whitespace
14-
- repo: https://gitee.com/hubert22/black
15-
rev: 22.10.0
14+
- repo: https://github.com/psf/black
15+
rev: 23.3.0
1616
hooks:
1717
- id: black
1818
- repo: https://github.com/crate-ci/typos

Cargo.toml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
[package]
2-
name = "silent"
3-
edition = "2021"
4-
authors = ["Hubert Shelley <hubertshelley@163.com>"]
5-
categories = ["web-programming::web", "web-programming::web-framework"]
6-
documentation = "https://docs.rs/"
7-
description = """
8-
Silent Web Framework
9-
"""
10-
homepage = "https://github.com/hubertshelley/silent"
11-
keywords = ["web", "web-framework"]
12-
license = "Apache-2.0"
13-
readme = "./readme.md"
14-
repository = "https://github.com/hubertshelley/silent"
15-
version = "0.1.0"
16-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
17-
18-
[dependencies]
1+
[workspace]
2+
members = ["silent", "examples/*"]
3+
default-members = ["silent", ]

deny.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ targets = [
3535
db-path = "~/.cargo/advisory-db"
3636
# The url(s) of the advisory databases to use
3737
# db-urls = ["https://github.com/rustsec/advisory-db"]
38-
db-urls = ["https://gitee.com/mirrors_RustSec/advisory-db"]
38+
db-urls = ["https://github.com/rustsec/advisory-db"]
3939
# The lint level for security vulnerabilities
4040
vulnerability = "deny"
4141
# The lint level for unmaintained crates
@@ -73,11 +73,11 @@ unlicensed = "allow"
7373
allow = [
7474
"MIT",
7575
"Apache-2.0",
76-
"Apache-2.0 WITH LLVM-exception",
77-
"ISC",
76+
# "Apache-2.0 WITH LLVM-exception",
77+
# "ISC",
7878
"Unicode-DFS-2016",
79-
"BSD-3-Clause",
80-
"BSD-2-Clause",
79+
# "BSD-3-Clause",
80+
# "BSD-2-Clause",
8181
]
8282
# List of explicitly disallowed licenses
8383
# See https://spdx.org/licenses/ for list of possible licenses
@@ -196,7 +196,7 @@ unknown-git = "warn"
196196
# List of URLs for allowed crate registries. Defaults to the crates.io index
197197
# if not specified. If it is specified but empty, no registries are allowed.
198198
allow-registry = [
199-
# "https://github.com/rust-lang/crates.io-index",
199+
"https://github.com/rust-lang/crates.io-index",
200200
"https://mirrors.ustc.edu.cn/crates.io-index",
201201
]
202202
# List of URLs for allowed Git repositories

examples/hello-world/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/hello-world/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "example-hello-world"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
silent = { version = "0.1.0", path = "../../silent" }

examples/hello-world/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use silent::prelude::*;
2+
3+
fn main() {
4+
logger::fmt().with_max_level(Level::INFO).init();
5+
let route = Route::new("").get(|_req| async { Ok("hello world") });
6+
Server::new().bind_route(route).run();
7+
}

examples/path_params/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "path_params"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
silent = { version = "0.1.0", path = "../../silent" }

examples/path_params/src/main.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use silent::prelude::*;
2+
3+
fn main() {
4+
logger::fmt().with_max_level(Level::INFO).init();
5+
// 定义路由
6+
let route = Route::new("path_params")
7+
.append(Route::new("<key:str>/str").get(hello_world))
8+
.append(Route::new("<key:int>/int").get(hello_world))
9+
.append(Route::new("<key:uuid>/uuid").get(hello_world))
10+
.append(Route::new("<key:path>/path").get(hello_world))
11+
.append(Route::new("<key:full_path>/full_path").get(hello_world))
12+
.append(Route::new("<key:*>/*").get(hello_world))
13+
.append(Route::new("<key:**>/**").get(hello_world))
14+
.append(Route::new("<key>").get(hello_world))
15+
.append(Route::new("<key:other>/other").get(hello_world));
16+
println!("{:?}", route);
17+
Server::new().bind_route(route).run();
18+
}
19+
20+
// 定义处理方法
21+
async fn hello_world(req: Request) -> Result<String, SilentError> {
22+
let path_params = req.get_path_params("key").unwrap();
23+
match path_params {
24+
PathParam::String(str) => Ok(format!("str {}", str)),
25+
PathParam::Int(int) => Ok(format!("int {}", int)),
26+
PathParam::UUid(uuid) => Ok(format!("uuid {}", uuid)),
27+
PathParam::Path(path) => Ok(format!("path {}", path)),
28+
}
29+
}

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Silent 是一个简单的基于Hyper的Web框架,它的目标是提供一个
66

77
### 目标
88

9-
- [ ] 路由
9+
- [x] 路由
1010
- [ ] 中间件
1111
- [ ] 静态文件
1212
- [ ] 模板
1313
- [ ] 数据库
14-
- [ ] 日志
14+
- [x] 日志 (使用了tracing)
1515
- [ ] 配置
1616
- [ ] 会话
1717
- [ ] 安全

0 commit comments

Comments
 (0)