made base parameter optional

This commit is contained in:
Edward Shen 2019-05-01 17:16:54 -04:00
parent c83190ada6
commit 0f4ca23655
Signed by: edward
GPG key ID: F350507060ED6C90
3 changed files with 9 additions and 6 deletions

View file

@ -12,7 +12,7 @@ pub struct EndpointConfig {
#[derive(Deserialize, Serialize, Debug, Clone)] #[derive(Deserialize, Serialize, Debug, Clone)]
pub struct WebsiteConfig { pub struct WebsiteConfig {
pub label: String, pub label: String,
pub base: String, pub base: Option<String>,
pub endpoints: Vec<EndpointConfig>, pub endpoints: Vec<EndpointConfig>,
} }

View file

@ -1,5 +1,6 @@
extern crate actix; extern crate actix;
extern crate actix_web; extern crate actix_web;
extern crate chrono;
extern crate env_logger; extern crate env_logger;
extern crate reqwest; extern crate reqwest;
extern crate ron; extern crate ron;
@ -7,7 +8,6 @@ extern crate serde;
extern crate tokio; extern crate tokio;
#[macro_use] #[macro_use]
extern crate tera; extern crate tera;
extern crate chrono;
mod config; mod config;
mod handlers; mod handlers;
@ -68,8 +68,7 @@ fn main() {
tokio::spawn( tokio::spawn(
Interval::new_interval(Duration::from_secs(config.refresh_time)) Interval::new_interval(Duration::from_secs(config.refresh_time))
.for_each(move |_| { .for_each(move |_| {
let state = Arc::clone(&clone_state); update_state(Arc::clone(&clone_state));
update_state(state);
Ok(()) Ok(())
}) })
.map_err(|_| ()), .map_err(|_| ()),

View file

@ -86,8 +86,12 @@ fn get_result(
} }
} }
fn get_url(base: &String, path: &String, port: Option<u16>) -> Result<String, UrlError> { fn get_url(base: &Option<String>, path: &String, port: Option<u16>) -> Result<String, UrlError> {
let mut url = Url::parse(base)?.join(path)?; let mut url = if let Some(base) = base {
Url::parse(base)?.join(path)?
} else {
Url::parse(path)?
};
if let Err(e) = url.set_port(port) { if let Err(e) = url.set_port(port) {
println!("{:?}", e); println!("{:?}", e);
} }