diff options
Diffstat (limited to 'rust/src')
-rw-r--r-- | rust/src/main.rs | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/rust/src/main.rs b/rust/src/main.rs index 486aa6f..2ccdcee 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -1,5 +1,35 @@ mod structs; -fn main() { - println!("Hello, world!"); +use actix_web::{web, App, HttpServer}; +use sqlx::mysql::{MySqlPool, MySqlPoolOptions}; + +#[derive(Clone)] +struct AppState { + pool: MySqlPool, +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + const DB_URL: &str = "mysql://root:@127.0.0.1:3306/balalaika"; + + let pool: MySqlPool = MySqlPoolOptions::new() + .max_connections(10) + .connect(DB_URL) + .await + .unwrap(); + + let app_state = AppState { pool }; + + HttpServer::new(move || { + App::new() + .app_data(web::Data::new(app_state.clone())) + .route("/", web::get().to(root)) + }) + .bind(("127.0.0.1", 8000))? + .run() + .await +} + +async fn root() -> String { + String::from("Server is up and running") } |