Skip to content

Commit

Permalink
Merge pull request #33 from aleeusgr/review-main
Browse files Browse the repository at this point in the history
add a route, add a handler, move handlers to lib.rs
  • Loading branch information
aleeusgr authored Jan 8, 2024
2 parents dc225da + 1763cf6 commit 4fe92e6
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 3 deletions.
183 changes: 182 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ console-subscriber = { version = "0.1", default-features = false, features = [ "
const_format = "0.2"
futures = "0.3"
headers = "0.3"
image = "0.24"
http = "0.2"
http-serde = "1.1"
hyper = "0.14"
Expand Down
1 change: 1 addition & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod my;
7 changes: 7 additions & 0 deletions src/handlers/my.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

// this is a handler, a function that is used in a Router
// A handler is an async function that accepts zero or more “extractors” as arguments and returns something that can be converted into a response.
pub async fn say_hello() -> String {
// integrate new functionality here:
return "Hello!!!".to_string();
}
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ pub mod settings;
pub mod tracer;
pub mod tracing_layers;

use axum::{
Json,
response::{Html, IntoResponse},
http::{StatusCode, Uri, header::{self, HeaderMap, HeaderName}},
};
use std::path::PathBuf;
use std::io::{BufWriter, Cursor};
use image::ImageFormat;

/// Test utilities.
#[cfg(any(test, feature = "test_utils"))]
#[cfg_attr(docsrs, doc(cfg(feature = "test_utils")))]
Expand All @@ -24,3 +33,21 @@ pub mod test_utils;
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
// stream.
pub async fn get_image() -> impl axum::response::IntoResponse {
let img_path = PathBuf::from("assets/").join("a_logo.png");
let image = image::io::Reader::open(&img_path).unwrap().decode().unwrap();
let mut buffer = BufWriter::new(Cursor::new(Vec::new()));
image.write_to(&mut buffer, ImageFormat::Png).unwrap();
let bytes: Vec<u8> = buffer.into_inner().unwrap().into_inner();
(
axum::response::AppendHeaders([(header::CONTENT_TYPE, "image/png")]),
bytes
// image.into_bytes()
)
}

pub async fn html() -> Html<&'static str> {
Html("<p>Hello, World!</p>")
}
// roadmap - show webcam on laptop screen.
Loading

0 comments on commit 4fe92e6

Please sign in to comment.