Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use reqwest to replace isahc #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ serde_yaml = "0.9.21"
clap = {version = "4.3.8", features = ["derive", "cargo"]}
thiserror = "1.0.40"
rand = "0.8.5"
isahc = "1.7"
reqwest = { version = "0.12.5", default-features = false, features = ["rustls-tls"] }
phf = { version = "0.11", features = ["macros"] }
# linked list to store the containers in the order they appear in the docker-compose.yaml
indexmap = { version = "2.0.0", features = ["serde"] }

# https://github.com/sfackler/rust-openssl/issues/1021
openssl = { version = "0.10", features = ["vendored"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

[profile.release]
debug = false
12 changes: 5 additions & 7 deletions src/file_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::io::Read;
use std::{fs::File, process::exit};

use isahc::ReadResponseExt;

use serde_yaml::{Mapping, Value};

use crate::exporters::excalidraw_config::DEFAULT_CONFIG;
Expand Down Expand Up @@ -30,8 +28,8 @@ pub fn get_excalidraw_config(file_path: &str) -> ExcalidrawConfig {
}
}

pub fn get_docker_compose_content(file_path: &str) -> Mapping {
let file_content = match get_file_content(file_path) {
pub async fn get_docker_compose_content(file_path: &str) -> Mapping {
let file_content = match get_file_content(file_path).await {
Ok(content) => content,
Err(err) => {
println!("{}", err);
Expand Down Expand Up @@ -81,10 +79,10 @@ fn read_yaml_file(file_path: &str) -> Result<String, ExcalidockerError> {

/// Get file content as a String.
/// Both remote (f.e. from Github) and local files are supported
fn get_file_content(file_path: &str) -> Result<String, ExcalidockerError> {
async fn get_file_content(file_path: &str) -> Result<String, ExcalidockerError> {
if file_path.starts_with("http") {
let url = rewrite_github_url(file_path);
let mut response = match isahc::get(url) {
let response = match reqwest::get(url).await {
Ok(rs) => rs,
Err(err) => {
return Err(RemoteFileFailedRead {
Expand All @@ -93,7 +91,7 @@ fn get_file_content(file_path: &str) -> Result<String, ExcalidockerError> {
})
}
};
match response.text() {
match response.text().await {
Ok(data) => Ok(data),
Err(err) => Err(RemoteFileFailedRead {
path: file_path.to_string(),
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ struct RectangleStruct {
pub bound_elements: Vec<BoundElement>,
}

fn main() {
#[tokio::main]
async fn main() {
let cli = Cli::parse();
let excalidraw_config: ExcalidrawConfig =
file_utils::get_excalidraw_config(cli.config_path.as_str());
Expand All @@ -164,7 +165,7 @@ fn main() {

let input_path = &cli.input_path.unwrap();
let input_filepath = input_path.as_str();
let docker_compose_yaml = file_utils::get_docker_compose_content(input_filepath);
let docker_compose_yaml = file_utils::get_docker_compose_content(input_filepath).await;

let alignment_mode = excalidraw_config.alignment.mode.as_str();
let (x_margin, y_margin, x_alignment_factor, y_alignment_factor) = margins(alignment_mode);
Expand Down