1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00
This commit is contained in:
Rob Ede
2022-02-18 02:44:02 +00:00
parent aca1dab890
commit fbd3b228e9
48 changed files with 103 additions and 261 deletions

View File

@ -20,10 +20,7 @@ async fn index(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
}
#[get("/{user}/{data}")]
async fn user(
hb: web::Data<Handlebars<'_>>,
path: web::Path<(String, String)>,
) -> HttpResponse {
async fn user(hb: web::Data<Handlebars<'_>>, path: web::Path<(String, String)>) -> HttpResponse {
let info = path.into_inner();
let data = json!({
"user": info.0,
@ -72,10 +69,7 @@ fn not_found<B>(res: ServiceResponse<B>) -> Result<ErrorHandlerResponse<BoxBody>
}
// Generic error handler.
fn get_error_response<B>(
res: &ServiceResponse<B>,
error: &str,
) -> HttpResponse<BoxBody> {
fn get_error_response<B>(res: &ServiceResponse<B>, error: &str) -> HttpResponse<BoxBody> {
let request = res.request();
// Provide a fallback to a simple plain text response in case an error occurs during the

View File

@ -33,8 +33,7 @@ async fn main() -> std::io::Result<()> {
println!("Listening on: 127.0.0.1:8080, open browser and visit have a try!");
HttpServer::new(|| {
let tera =
Tera::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")).unwrap();
let tera = Tera::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")).unwrap();
App::new()
.app_data(web::Data::new(tera))

View File

@ -13,9 +13,7 @@ impl ResponseError for MyErr {}
#[allow(unused_must_use)] // ywrite_min causes warning: unused borrow that must be used
#[get("/")]
async fn index(
query: web::Query<HashMap<String, String>>,
) -> Result<HttpResponse, Error> {
async fn index(query: web::Query<HashMap<String, String>>) -> Result<HttpResponse, Error> {
// `ywrite_min` is work in progress check your templates before put in production
// or use `ywrite_html`
Ok(HttpResponse::Ok()