aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src
diff options
context:
space:
mode:
Diffstat (limited to 'planetwars-server/src')
-rw-r--r--planetwars-server/src/lib.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/planetwars-server/src/lib.rs b/planetwars-server/src/lib.rs
index ad7741c..123fdab 100644
--- a/planetwars-server/src/lib.rs
+++ b/planetwars-server/src/lib.rs
@@ -28,11 +28,9 @@ use axum::{
Router,
};
-// TODO: make these configurable
-const SIMPLEBOT_PATH: &str = "../simplebot/simplebot.py";
-
type ConnectionPool = bb8::Pool<DieselConnectionManager<PgConnection>>;
+// this should probably be modularized a bit as the config grows
#[derive(Serialize, Deserialize)]
pub struct GlobalConfig {
/// url for the postgres database
@@ -59,6 +57,9 @@ pub struct GlobalConfig {
pub registry_admin_password: String,
}
+// TODO: do we still need this? Is there a better way?
+const SIMPLEBOT_PATH: &str = "../simplebot/simplebot.py";
+
pub async fn seed_simplebot(config: &GlobalConfig, pool: &ConnectionPool) {
let conn = pool.get().await.expect("could not get database connection");
// This transaction is expected to fail when simplebot already exists.
@@ -88,7 +89,7 @@ pub type DbPool = Pool<DieselConnectionManager<PgConnection>>;
pub async fn prepare_db(config: &GlobalConfig) -> DbPool {
let manager = DieselConnectionManager::<PgConnection>::new(&config.database_url);
let pool = bb8::Pool::builder().build(manager).await.unwrap();
- seed_simplebot(&config, &pool).await;
+ seed_simplebot(config, &pool).await;
pool
}
@@ -160,11 +161,6 @@ pub async fn run_app() {
axum::Server::bind(&addr).serve(api_service).await.unwrap();
}
-#[derive(Deserialize)]
-pub struct Configuration {
- pub database_url: String,
-}
-
// we can also write a custom extractor that grabs a connection from the pool
// which setup is appropriate depends on your application
pub struct DatabaseConnection(PooledConnection<'static, DieselConnectionManager<PgConnection>>);