feat: 首次提交

This commit is contained in:
caoqianming 2025-07-10 16:01:57 +08:00
commit cdcdf8bd40
7 changed files with 2701 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

2643
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

10
Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "xtrs"
version = "0.1.0"
edition = "2024"
[dependencies]
salvo = "0.80.0"
tokio = { version = "1.46.1", features = ["macros"] }
tracing = "0.1.41"
tracing-subscriber = "0.3.19"

14
src/main.rs Normal file
View File

@ -0,0 +1,14 @@
use salvo::prelude::*;
mod url;
mod system;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let service = url::init();
let acceptor = TcpListener::new("0.0.0.0:5800").bind().await;
Server::new(acceptor).serve(service).await;
}

12
src/system/handler.rs Normal file
View File

@ -0,0 +1,12 @@
use salvo::prelude::*;
#[handler]
pub async fn hello_msg(req: &mut Request, res: &mut Response) {
let msg = req.param("msg").unwrap_or("world");
res.render(Text::Html(format!("Hello, {}!", msg)));
}
#[handler]
pub async fn hello() -> &'static str {
"Hello World"
}

8
src/system/mod.rs Normal file
View File

@ -0,0 +1,8 @@
mod handler;
use salvo::Router;
pub fn init_router() -> Router {
Router::new().push(
Router::with_path("hello/{msg}/").get(handler::hello_msg)
)
}

13
src/url.rs Normal file
View File

@ -0,0 +1,13 @@
use salvo::{Router, Service};
use crate::system;
pub fn init() -> Service {
let router = init_router();
Service::new(router)
}
pub fn init_router() -> Router{
let router = Router::new();
router.push(
system::init_router()
)
}