Skip to content

Commit

Permalink
update craft example
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Sep 23, 2024
1 parent 22d1b3c commit 2a121ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions crates/craft-macros/examples/example-add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@ use salvo::prelude::*;
use salvo_craft_macros::craft;
use std::sync::Arc;

#[tokio::main]
async fn main() {
let opts = Arc::new(Opts::new(1));
let router = Router::new()
.push(Router::with_path("add1").get(opts.add1()))
.push(Router::with_path("add2").get(opts.add2()))
.push(Router::with_path("add3").get(Opts::add3()));
let doc = OpenApi::new("Example API", "0.0.1").merge_router(&router);
let router = router
.push(doc.into_router("/api-doc/openapi.json"))
.push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui"));
let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
Server::new(acceptor).serve(router).await;
}

#[derive(Clone)]
pub struct Opts {
state: i64,
Expand Down Expand Up @@ -53,3 +38,18 @@ impl Opts {
(*left + *right).to_string()
}
}

#[tokio::main]
async fn main() {
let opts = Arc::new(Opts::new(1));
let router = Router::new()
.push(Router::with_path("add1").get(opts.add1()))
.push(Router::with_path("add2").get(opts.add2()))
.push(Router::with_path("add3").get(Opts::add3()));
let doc = OpenApi::new("Example API", "0.0.1").merge_router(&router);
let router = router
.push(doc.into_router("/api-doc/openapi.json"))
.push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui"));
let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
Server::new(acceptor).serve(router).await;
}
30 changes: 15 additions & 15 deletions examples/craft/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ use salvo::oapi::extract::*;
use salvo::prelude::*;
use std::sync::Arc;

#[tokio::main]
async fn main() {
let opts = Arc::new(Opts::new(1));
let router = Router::new()
.push(Router::with_path("add1").get(opts.add1()))
.push(Router::with_path("add2").get(opts.add2()))
.push(Router::with_path("add3").get(Opts::add3()));
let doc = OpenApi::new("Example API", "0.0.1").merge_router(&router);
let router = router
.push(doc.into_router("/api-doc/openapi.json"))
.push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui"));
let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
Server::new(acceptor).serve(router).await;
}

#[derive(Clone)]
pub struct Opts {
state: i64,
Expand Down Expand Up @@ -50,3 +35,18 @@ impl Opts {
(*left + *right).to_string()
}
}

#[tokio::main]
async fn main() {
let opts = Arc::new(Opts::new(1));
let router = Router::new()
.push(Router::with_path("add1").get(opts.add1()))
.push(Router::with_path("add2").get(opts.add2()))
.push(Router::with_path("add3").get(Opts::add3()));
let doc = OpenApi::new("Example API", "0.0.1").merge_router(&router);
let router = router
.push(doc.into_router("/api-doc/openapi.json"))
.push(SwaggerUi::new("/api-doc/openapi.json").into_router("swagger-ui"));
let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
Server::new(acceptor).serve(router).await;
}

0 comments on commit 2a121ef

Please sign in to comment.