Skip to content

Commit

Permalink
update salvo version
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Dec 14, 2023
1 parent 63b788f commit 993962d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
39 changes: 34 additions & 5 deletions src/template/src/main_template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ use crate::db::init_db_conn;
{{#if is_mongodb}}
use crate::db::init_db_conn;
{{/if}}
use tokio::signal;
use tracing::info;
use crate::middleware::handle_404::handle_404;
use crate::routers::router;
use config::{CERT_KEY, CFG};
use salvo::server::ServerHandle;
use salvo::catcher::Catcher;
use salvo::conn::rustls::{Keycert, RustlsConfig};
use salvo::prelude::*;
Expand Down Expand Up @@ -83,10 +86,9 @@ async fn main() {
.await;
let server = Server::new(acceptor);
let handle = server.handle();
tokio::spawn(shutdown_signal(handle));
server.serve(service).await;
handle.stop_graceful(std::time::Duration::from_secs(5));

}
}
false => {
println!(
"📖 {{swagger_api_page}}: http://{}/swagger-ui",
Expand All @@ -100,9 +102,10 @@ async fn main() {
let acceptor = TcpListener::new(&CFG.server.address).bind().await;
let server = Server::new(acceptor);
let handle = server.handle();
tokio::spawn(shutdown_signal(handle));
server.serve(service).await;
handle.stop_graceful(std::time::Duration::from_secs(5)); }
};
}
}
}

fn init_log() {
Expand All @@ -116,6 +119,32 @@ fn init_log() {
.init();
tracing::info!("log level: {}", &CFG.log.filter_level);
}

async fn shutdown_signal(handle: ServerHandle) {
let ctrl_c = async {
signal::ctrl_c()
.await
.expect("failed to install Ctrl+C handler");
};

#[cfg(unix)]
let terminate = async {
signal::unix::signal(signal::unix::SignalKind::terminate())
.expect("failed to install signal handler")
.recv()
.await;
};

#[cfg(not(unix))]
let terminate = std::future::pending::<()>();

tokio::select! {
_ = ctrl_c => info!("ctrl_c signal received"),
_ = terminate => info!("terminate signal received"),
}
handle.stop_graceful(std::time::Duration::from_secs(60));
}

#[cfg(test)]
mod tests {
use salvo::prelude::*;
Expand Down
4 changes: 2 additions & 2 deletions src/template/src/routers/demo.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
use askama::Template;
{{/if}}
{{#if is_web_site}}
use salvo::{endpoint, writing::Text, Request, Response};
use salvo::{oapi::endpoint, writing::Text, Request, Response};
{{else}}
use salvo::endpoint;
use salvo::oapi::endpoint;
{{/if}}
use crate::app_response::AppResult;
{{#if is_web_site}}
Expand Down
4 changes: 2 additions & 2 deletions src/template/src/routers/static_routers.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use rust_embed::RustEmbed;
{{#if need_db_conn}}
use salvo::{Router, serve_static::static_embed, endpoint, Response, http::ResBody, hyper::body::Bytes};
use salvo::{Router, serve_static::static_embed, oapi::endpoint, Response, http::ResBody, hyper::body::Bytes};
{{else}}
use salvo::{Router, endpoint, Response, http::ResBody, hyper::body::Bytes};
use salvo::{Router, oapi::endpoint, Response, http::ResBody, hyper::body::Bytes};
{{/if}}
#[derive(RustEmbed)]
#[folder = "assets"]
Expand Down
4 changes: 2 additions & 2 deletions src/template/src/routers/user.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};
use askama::Template;
use salvo::{
endpoint,
oapi::endpoint,
http::cookie::Cookie,
oapi::extract::{JsonBody, PathParam},
writing::{Redirect, Text},
Expand Down Expand Up @@ -114,7 +114,7 @@ use crate::{
services::user,
};
use salvo::{
endpoint,
oapi::endpoint,
http::cookie::Cookie,
oapi::extract::{JsonBody, PathParam},
Request, Response,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/create_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn write_project_file(
"jsonwebtoken": "8.3.0",
"once_cell": "1.18.0",
"salvo": {
"version": "0.60",
"version": "0.63",
"features": ["anyhow", "logging", "cors", "oapi", "jwt-auth", "rustls", "catch-panic","cookie","serve-static"]
},
"serde": "1.0.188",
Expand Down

0 comments on commit 993962d

Please sign in to comment.