Browse Source

some commit

main
Alexey Velikiy 3 years ago
parent
commit
851d7221c2
  1. 34
      src/grafana_service.rs

34
src/grafana_service.rs

@ -47,10 +47,11 @@ impl GrafanaService {
Ok(()) Ok(())
} }
async fn get(&self, suburl:&str) -> types::Result<()> { async fn get(&self, suburl:&str) -> types::Result<serde_json::Value> {
let req = Request::builder() let req = Request::builder()
.method(Method::GET) .method(Method::GET)
.uri(self.url.to_owned() + suburl) .uri(self.url.to_owned() + suburl)
.header("Accept", "application/json")
.header("Authorization", format!("Bearer {}", self.api_key)) .header("Authorization", format!("Bearer {}", self.api_key))
.body(Body::empty()) .body(Body::empty())
.unwrap(); .unwrap();
@ -61,20 +62,21 @@ impl GrafanaService {
println!(""); println!("");
let body = hyper::body::aggregate(res).await?; let body = hyper::body::aggregate(res).await?;
let mut reader = body.reader(); let reader = body.reader();
let mut line = String::new(); let result: serde_json::Value = serde_json::from_reader(reader)?;
loop { // let mut line = String::new();
match reader.read_line(&mut line) { // loop {
Ok(s) => { // match reader.read_line(&mut line) {
if s == 0 { // Ok(s) => {
break; // if s == 0 {
} // break;
println!("{}", line); // }
line.clear(); // println!("{}", line);
}, // line.clear();
Err(_) => break // },
} // Err(_) => break
} // }
Ok(()) // }
Ok(result)
} }
} }

Loading…
Cancel
Save