mirror of
https://github.com/actix/actix-web.git
synced 2024-11-18 07:35:36 +00:00
update diesel example
This commit is contained in:
parent
17c27ef42d
commit
74d0656d27
1 changed files with 6 additions and 6 deletions
|
@ -19,8 +19,8 @@ extern crate actix_web;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
|
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use actix_web::{http, middleware,
|
use actix_web::{http, server, middleware,
|
||||||
App, HttpServer, HttpRequest, HttpResponse, Error, AsyncResponder};
|
App, Path, State, HttpResponse, AsyncResponder, FutureResponse};
|
||||||
|
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use r2d2_diesel::ConnectionManager;
|
use r2d2_diesel::ConnectionManager;
|
||||||
|
@ -34,12 +34,12 @@ use db::{CreateUser, DbExecutor};
|
||||||
|
|
||||||
|
|
||||||
/// State with DbExecutor address
|
/// State with DbExecutor address
|
||||||
struct App {
|
struct AppState {
|
||||||
db: Addr<Syn, DbExecutor>,
|
db: Addr<Syn, DbExecutor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Async request handler
|
/// Async request handler
|
||||||
fn index(name: Path<(String,)>, state: State<App>) -> FutureResponse<HttpResponse> {
|
fn index(name: Path<String>, state: State<AppState>) -> FutureResponse<HttpResponse> {
|
||||||
// send async `CreateUser` message to a `DbExecutor`
|
// send async `CreateUser` message to a `DbExecutor`
|
||||||
state.db.send(CreateUser{name: name.into_inner()})
|
state.db.send(CreateUser{name: name.into_inner()})
|
||||||
.from_err()
|
.from_err()
|
||||||
|
@ -66,8 +66,8 @@ fn main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start http server
|
// Start http server
|
||||||
let _addr = HttpServer::new(move || {
|
server::new(move || {
|
||||||
App::with_state(State{db: addr.clone()})
|
App::with_state(AppState{db: addr.clone()})
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
.resource("/{name}", |r| r.method(http::Method::GET).with2(index))})
|
.resource("/{name}", |r| r.method(http::Method::GET).with2(index))})
|
||||||
|
|
Loading…
Reference in a new issue