1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 01:51:23 +02:00

cleanup examples

This commit is contained in:
Nikolay Kim
2017-12-20 16:32:31 -08:00
parent 4dd3382ac7
commit 3c5fd18e02
5 changed files with 18 additions and 17 deletions

View File

@ -9,19 +9,20 @@ struct State {
template: tera::Tera, // <- store tera template in application state
}
fn index(req: HttpRequest<State>) -> HttpResponse {
fn index(req: HttpRequest<State>) -> Result<HttpResponse> {
let s = if let Some(name) = req.query().get("name") { // <- submitted form
let mut ctx = tera::Context::new();
ctx.add("name", name);
ctx.add("text", &"Welcome!".to_owned());
req.state().template.render("user.html", &ctx).unwrap()
req.state().template.render("user.html", &ctx)
.map_err(|_| error::ErrorInternalServerError("Template error"))?
} else {
req.state().template.render("index.html", &tera::Context::new()).unwrap()
req.state().template.render("index.html", &tera::Context::new())
.map_err(|_| error::ErrorInternalServerError("Template error"))?
};
httpcodes::HTTPOk.build()
.content_type("text/html")
.body(s)
.unwrap()
Ok(httpcodes::HTTPOk.build()
.content_type("text/html")
.body(s)?)
}
fn main() {