feat: add handler module and update main.rs

This commit is contained in:
2024-02-11 17:03:32 +01:00
parent 77b684ac42
commit c4f50af39a
7 changed files with 810 additions and 24 deletions

3
src/handler/hello.rs Normal file
View File

@@ -0,0 +1,3 @@
pub async fn say_hello() -> &'static str {
"Hello, World!"
}

1
src/handler/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod hello;

View File

@@ -1 +1,2 @@
pub mod search;
pub mod search;
pub mod handler;

View File

@@ -1,13 +1,20 @@
use rustysearch::search::engine::SearchEngine;
use axum::{
routing::get,
Router,
};
fn main() {
let mut engine = SearchEngine::new(1.5, 0.75);
engine.index("https://www.rust-lang.org/", "Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety.");
engine.index("https://en.wikipedia.org/wiki/Rust_(programming_language)", "Rust is a multi-paradigm system programming language focused on safety, especially safe concurrency.");
#[tokio::main]
async fn main() {
// initialize tracing
tracing_subscriber::fmt::init();
// build our application with a route
let app = Router::new()
// `GET /` goes to `root`
.route("/", get(rustysearch::handler::hello::say_hello));
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
let query = "Rust programming language threads";
let results = engine.search(query);
for (url, score) in results {
println!("{}: {}", url, score);
}
}