Skip to content

Commit

Permalink
fix(feature): fix python feature
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Mar 23, 2024
1 parent 52c7a27 commit 7ac6b02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn main() {
if !is_server {
loop {
let now = Instant::now();
get("127.0.0.1:813/path", true).await.unwrap();
get("127.0.0.1:7076/path", true).await.unwrap();
println!("执行时间: {}", now.elapsed().as_millis());
}
} else {
Expand All @@ -53,7 +53,7 @@ async fn main() {
path_route!(&mut router, "/welcome" => welcome);
path_route!(&mut router, "/json" => json);

let mut server = Server::new("127.0.0.1", 813, router);
let mut server = Server::new("0.0.0.0", 7076, router);
server.run().await;
}
}
17 changes: 11 additions & 6 deletions src/models/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! # Oblivion Client
use crate::models::packet::{OED, OKE, OSC};

use crate::exceptions::{OblivionException, PyOblivionException};
use crate::exceptions::OblivionException;
#[cfg(feature = "python")]
use crate::exceptions::PyOblivionException;

use crate::utils::gear::Socket;
use crate::utils::generator::generate_key_pair;
Expand All @@ -20,13 +22,13 @@ use serde_json::{json, Value};

#[cfg_attr(feature = "python", pyclass)]
pub struct Response {
#[pyo3(get)]
#[cfg_attr(feature = "python", pyo3(get))]
pub header: String,
#[pyo3(get)]
#[cfg_attr(feature = "python", pyo3(get))]
pub content: Vec<u8>,
#[pyo3(get)]
#[cfg_attr(feature = "python", pyo3(get))]
pub olps: String,
#[pyo3(get)]
#[cfg_attr(feature = "python", pyo3(get))]
pub status_code: i32,
}

Expand Down Expand Up @@ -62,7 +64,10 @@ impl Response {
}

pub fn json(&mut self) -> Result<Value, OblivionException> {
Ok(from_str::<Value>(&self.text()?).unwrap())
match from_str::<Value>(&self.text()?) {
Ok(json) => Ok(json),
Err(_) => Err(OblivionException::BadBytes),
}
}
}

Expand Down

0 comments on commit 7ac6b02

Please sign in to comment.