-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charley <[email protected]>
- Loading branch information
1 parent
1b36132
commit 7364de2
Showing
6 changed files
with
41 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[workspace] | ||
members = [ "src/api","src/vmm", "src/cli"] | ||
members = ["src/api", "src/vmm", "src/cli"] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
use crate::types::{Config, Language, LogLevel}; | ||
use crate::types::{Language, LogLevel, YamlConfigFile}; | ||
use crate::utils::read_file; | ||
use reqwest::Client; | ||
use serde::Serialize; | ||
use std::error::Error; | ||
|
||
|
||
#[derive(Serialize, Debug)] | ||
pub struct HttpRunRequest { | ||
pub struct HttpVmmRequest { | ||
pub language: Language, | ||
pub env: String, | ||
pub code: String, | ||
pub log_level: LogLevel, | ||
} | ||
|
||
impl HttpRunRequest { | ||
pub fn new(config: Config) -> Self { | ||
impl HttpVmmRequest { | ||
pub fn new(config: YamlConfigFile) -> Self { | ||
let code: String = read_file(&config.code_path).expect("Error while reading the code file"); | ||
let env = read_file(&config.env_path).expect("Error while reading the environment file"); | ||
let language = config.language; | ||
let log_level = config.log_level; | ||
HttpRunRequest { | ||
HttpVmmRequest { | ||
language, | ||
env, | ||
code, | ||
log_level, | ||
} | ||
} | ||
} | ||
|
||
pub async fn run_request(request: HttpRunRequest) -> Result<(), Box<dyn Error>> { | ||
let client = Client::new(); | ||
let res = client | ||
.post("http://127.0.0.1:3000/run") | ||
.body(serde_json::to_string(&request)?) | ||
.send() | ||
.await?; | ||
println!("Response Status: {}", res.status()); | ||
let body = res.text().await?; | ||
println!("Response body: {}", body); | ||
Ok(()) | ||
pub async fn post(request: HttpVmmRequest) -> Result<(), Box<dyn Error>> { | ||
let client = Client::new(); | ||
let res = client | ||
.post("http://127.0.0.1:3000/run") | ||
.body(serde_json::to_string(&request)?) | ||
.send() | ||
.await?; | ||
println!("Response Status: {}", res.status()); | ||
let body = res.text().await?; | ||
println!("Response body: {}", body); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters