move get url into own function
This commit is contained in:
parent
872735d944
commit
bc87f7e346
2 changed files with 12 additions and 6 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1,3 +1,5 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "adler32"
|
name = "adler32"
|
||||||
version = "1.0.3"
|
version = "1.0.3"
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -2,7 +2,7 @@ extern crate reqwest;
|
||||||
extern crate ron;
|
extern crate ron;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
|
||||||
use reqwest::{Client, Url};
|
use reqwest::{Client, Url, UrlError};
|
||||||
use ron::de::from_str;
|
use ron::de::from_str;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
@ -47,11 +47,7 @@ fn main() -> Result<(), Box<Error>> {
|
||||||
for website_conf in config.websites {
|
for website_conf in config.websites {
|
||||||
for endpoint in website_conf.endpoints {
|
for endpoint in website_conf.endpoints {
|
||||||
let (label, path, port, code, body) = get_endpoint_info(endpoint);
|
let (label, path, port, code, body) = get_endpoint_info(endpoint);
|
||||||
let mut url = Url::parse(&website_conf.base)?.join(&path)?;
|
let url = get_url(&website_conf.base, &path, port)?;
|
||||||
if let Err(e) = url.set_port(port) {
|
|
||||||
println!("{:?}", e);
|
|
||||||
}
|
|
||||||
let url = url.into_string();
|
|
||||||
let mut res = client.get(&url).send()?;
|
let mut res = client.get(&url).send()?;
|
||||||
|
|
||||||
let does_code_match = res.status() == code;
|
let does_code_match = res.status() == code;
|
||||||
|
@ -93,6 +89,14 @@ fn main() -> Result<(), Box<Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_url(base: &String, path: &String, port: Option<u16>) -> Result<String, UrlError> {
|
||||||
|
let mut url = Url::parse(base)?.join(path)?;
|
||||||
|
if let Err(e) = url.set_port(port) {
|
||||||
|
println!("{:?}", e);
|
||||||
|
}
|
||||||
|
Ok(url.into_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn get_endpoint_info(endpoint: EndpointConf) -> (String, String, Option<u16>, u16, String) {
|
fn get_endpoint_info(endpoint: EndpointConf) -> (String, String, Option<u16>, u16, String) {
|
||||||
let path = endpoint.endpoint.unwrap_or_default();
|
let path = endpoint.endpoint.unwrap_or_default();
|
||||||
let label = endpoint.label.unwrap_or_else(|| path.clone());
|
let label = endpoint.label.unwrap_or_else(|| path.clone());
|
||||||
|
|
Loading…
Reference in a new issue