Skip to content

Commit

Permalink
docs: simplify axum example
Browse files Browse the repository at this point in the history
  • Loading branch information
brianheineman committed Aug 12, 2024
1 parent 9afd616 commit e955a1e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions examples/axum_embedded/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,19 @@ async fn main() -> Result<()> {
postgresql.stop().await?;
postgresql.start().await?;

info!("Enabling extension");
let pool = PgPool::connect(database_url.as_str()).await?;
enable_extension(&pool).await?;

info!("Setup connection pool");
let db_connection_str = settings.url(database_name);
let pool = PgPoolOptions::new()
.max_connections(5)
.acquire_timeout(Duration::from_secs(3))
.connect(&db_connection_str)
.connect(&database_url)
.await?;

info!("Enabling extension");
enable_extension(&pool).await?;

info!("Start application");
let app = Router::new().route("/", get(extensions)).with_state(pool);

// run it with hyper
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
info!("Listening on {}", listener.local_addr()?);
axum::serve(listener, app).await?;
Expand All @@ -91,9 +88,6 @@ async fn extensions(State(pool): State<PgPool>) -> Result<Json<Vec<String>>, (St
.map_err(internal_error)
}

fn internal_error<E>(err: E) -> (StatusCode, String)
where
E: std::error::Error,
{
fn internal_error<E: std::error::Error>(err: E) -> (StatusCode, String) {
(StatusCode::INTERNAL_SERVER_ERROR, err.to_string())
}

0 comments on commit e955a1e

Please sign in to comment.