diff --git a/gcd-web/src/main.rs b/gcd-web/src/main.rs index 1f36a4f..325f8f0 100644 --- a/gcd-web/src/main.rs +++ b/gcd-web/src/main.rs @@ -1,22 +1,45 @@ use actix_web::{web, App, HttpResponse, HttpServer}; +use serde::Deserialize; + +#[derive(Deserialize)] +struct GcdParams { + a: u64, + b: u64, +} + +fn gcd(mut a: u64, mut b: u64) -> u64 { + while a > 0 { + if a < b { + let temp = a; + a = b; + b = temp; + } + + a = a % b; + } + + b +} fn main() { let server = HttpServer::new(|| { App::new() .route("/", web::get().to(get_index)) + .route("/gcd", web::post().to(post_gcd)) }); println!("Serving on http://localhost:3300"); - server.bind("127.0.0.1:3300").expect("error binding server to address") - .run().expect("error running server") + server + .bind("127.0.0.1:3300") + .expect("error binding server to address") + .run() + .expect("error running server") } fn get_index() -> HttpResponse { - HttpResponse::Ok() - .content_type("text/html") - .body( - r#" + HttpResponse::Ok().content_type("text/html").body( + r#"