restructured, added db connection pool
This commit is contained in:
14
src/main.rs
14
src/main.rs
@ -1,9 +1,15 @@
|
||||
use std::net::TcpListener;
|
||||
|
||||
use zero2prod::run;
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use zero2prod::configuration::get_configuration;
|
||||
use zero2prod::startup::run;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let listener = TcpListener::bind("127.0.0.1:8000").expect("Failed to bind random port");
|
||||
run(listener)?.await
|
||||
let config = get_configuration().expect("Failed to read configuration");
|
||||
let connection = PgPoolOptions::new()
|
||||
.max_connections(10).connect(&config.database.connection_string()).await.expect("Failed to connect to Postgres.");
|
||||
|
||||
let address = format!("127.0.0.1:{}", config.application_port);
|
||||
let listener = TcpListener::bind(address).expect("Failed to bind random port");
|
||||
run(listener, connection)?.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user