-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Silent] add Silent * [Silent] add Silent * Update ci.yml * Update ci.yml
- Loading branch information
1 parent
54f587a
commit d4b21b0
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,6 +181,8 @@ rust: | |
- colinbankier | ||
salvo: | ||
- chrislearn | ||
silent: | ||
- hubertshelley | ||
poem: | ||
- sunli829 | ||
axum: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "server" | ||
version = "0.0.0" | ||
edition = "2021" | ||
authors = ["Hubert Shelley <hubertshelley@163.com>"] | ||
|
||
[dependencies] | ||
async-trait = "0.1.68" | ||
silent = { version = "0.6" } | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
debug = false | ||
debug-assertions = false | ||
overflow-checks = false | ||
lto = true | ||
panic = "abort" | ||
incremental = false | ||
codegen-units = 1 | ||
rpath = false | ||
strip = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
framework: | ||
github: hubertshelley/silent | ||
version: "0.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::sync::Arc; | ||
use async_trait::async_trait; | ||
use silent::prelude::*; | ||
|
||
struct Index; | ||
|
||
#[async_trait] | ||
impl Handler for Index { | ||
async fn call(&self, _req: Request) -> Result<Response> { | ||
Ok(Response::empty()) | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut user_route = Route::new("user").append( | ||
Route::new("<id>").get( | ||
|req| async move { | ||
req.get_path_params::<String>("id") | ||
} | ||
), | ||
); | ||
user_route.get_handler_mut().insert( | ||
Method::POST, | ||
Arc::new(Index), | ||
); | ||
let mut route = Route::new("") | ||
.append( | ||
user_route | ||
); | ||
route.get_handler_mut().insert( | ||
Method::GET, | ||
Arc::new(Index), | ||
); | ||
Server::new().bind("0.0.0.0:3000".parse().unwrap()).bind_route(route).run(); | ||
} |