diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2024-09-26 13:56:04 +0200 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2024-09-26 13:56:04 +0200 |
commit | abad2ebad9c78e3978343aa0fc572a87dbf9fa78 (patch) | |
tree | 1afccd19ba25874af6069eacf1c81075631d904a /rust/src/main.rs | |
parent | 300c0fd9c956984d3a4d5275de4483a5e280d7db (diff) |
update rust code
Diffstat (limited to 'rust/src/main.rs')
-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") } |