feat: add salvo
This commit is contained in:
1436
__web/salvo/Cargo.lock
generated
Normal file
1436
__web/salvo/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
__web/salvo/Cargo.toml
Normal file
12
__web/salvo/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "salvo"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
salvo = "0.9"
|
||||||
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
|
||||||
3
__web/salvo/README.md
Normal file
3
__web/salvo/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Website:
|
||||||
|
https://github.com/salvo-rs/salvo/
|
||||||
|
|
||||||
31
__web/salvo/src/main.rs
Normal file
31
__web/salvo/src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
use salvo::prelude::*;
|
||||||
|
|
||||||
|
#[fn_handler]
|
||||||
|
async fn hello_world(req: &mut Request, _depot: &mut Depot, res: &mut Response) {
|
||||||
|
let mut output = String::with_capacity(1024);
|
||||||
|
output.push_str(&format!("request: {:#?}", req));
|
||||||
|
res.render_plain_text(&output);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fn_handler]
|
||||||
|
async fn print_json(res: &mut Response) {
|
||||||
|
res.render_json_text("{\"data\": \"hello\"}\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[fn_handler]
|
||||||
|
async fn send_redirect(res: &mut Response) {
|
||||||
|
res.redirect_temporary("https://hatter.ink/");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let router = Router::new().push(
|
||||||
|
Router::new().get(hello_world)
|
||||||
|
).push(
|
||||||
|
Router::new().path("json").get(print_json)
|
||||||
|
).push(
|
||||||
|
Router::new().path("redirect").get(send_redirect)
|
||||||
|
);
|
||||||
|
let server = Server::new(router);
|
||||||
|
server.bind(([0, 0, 0, 0], 7878)).await;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user