summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/liveops.rs6
-rw-r--r--src/main.rs25
-rw-r--r--src/services/db.rs7
-rw-r--r--src/services/mod.rs1
4 files changed, 27 insertions, 12 deletions
diff --git a/src/api/liveops.rs b/src/api/liveops.rs
index 355103d..de77eb7 100644
--- a/src/api/liveops.rs
+++ b/src/api/liveops.rs
@@ -1,8 +1,8 @@
-use actix_web::{get, web, Scope};
+use actix_web::{get, web, HttpResponse, Scope};
#[get("ping")]
-async fn ping() -> &'static str {
- "pong"
+async fn ping() -> HttpResponse {
+ HttpResponse::Ok().finish()
}
pub fn service() -> Scope {
diff --git a/src/main.rs b/src/main.rs
index ec04d93..5104428 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,14 +1,21 @@
-use std::time::Duration;
-
-use actix_web::{App, HttpServer};
+use actix_web::{web::Data, App, HttpServer};
+use exun::RawUnexpected;
mod api;
+mod services;
#[actix_web::main]
-async fn main() -> std::io::Result<()> {
- HttpServer::new(|| App::new().service(api::liveops()))
- .shutdown_timeout(1)
- .bind(("127.0.0.1", 8080))?
- .run()
- .await
+async fn main() -> Result<(), RawUnexpected> {
+ let sql_pool = services::db::initialize("password_database", "dbuser", "Demo1234").await?;
+ HttpServer::new(move || {
+ App::new()
+ .app_data(Data::new(sql_pool.clone()))
+ .service(api::liveops())
+ })
+ .shutdown_timeout(1)
+ .bind(("127.0.0.1", 8080))?
+ .run()
+ .await?;
+
+ Ok(())
}
diff --git a/src/services/db.rs b/src/services/db.rs
new file mode 100644
index 0000000..baf73e9
--- /dev/null
+++ b/src/services/db.rs
@@ -0,0 +1,7 @@
+use exun::*;
+use sqlx::MySqlPool;
+
+pub async fn initialize(db: &str, user: &str, password: &str) -> Result<MySqlPool, RawUnexpected> {
+ let url = format!("mysql://{user}:{password}@localhost/{db}");
+ MySqlPool::connect(&url).await.unexpect()
+}
diff --git a/src/services/mod.rs b/src/services/mod.rs
new file mode 100644
index 0000000..dec1023
--- /dev/null
+++ b/src/services/mod.rs
@@ -0,0 +1 @@
+pub mod db;