diff --git a/src/config/default.rs b/src/config/default.rs index 5b8901c..eddf43a 100644 --- a/src/config/default.rs +++ b/src/config/default.rs @@ -5,7 +5,7 @@ fn get_default_config() -> Config { server: ServerConfig { host: Option::Some(String::from("localhost")), port: Option::Some(8080), - workers: Option::Some(4) + workers: Option::Some(4), }, cloudflare: CloudflareConfig { email: String::from("something@something.com"), @@ -13,9 +13,9 @@ fn get_default_config() -> Config { domains: vec![ CloudflareDomainConfig { domain: String::from("IAmNotADomain.com"), - zone_id: String::from("IAmNotAZoneID") + zone_id: String::from("IAmNotAZoneID"), } - ] + ], }, ddns: DDNSConfig { domains: vec![ @@ -23,7 +23,7 @@ fn get_default_config() -> Config { domain: String::from("IAmNotADomain.com"), subdomains: vec![ String::from("ddns") - ] + ], } ] }, @@ -39,12 +39,12 @@ fn get_default_config() -> Config { subdomain: String::from("ddns"), targets: vec![ String::from("home") - ] + ], } - ] + ], } - ] + ], } - ] + ], } } \ No newline at end of file diff --git a/src/config/error.rs b/src/config/error.rs index 0d627a7..2af4d53 100644 --- a/src/config/error.rs +++ b/src/config/error.rs @@ -4,14 +4,14 @@ use std::fmt; #[derive(Debug)] pub struct ConfigError { description: String, - original_error: Option> + original_error: Option>, } impl ConfigError { pub fn new(description: &str, original_error: Option>) -> ConfigError { ConfigError { description: String::from(description), - original_error + original_error, } } } @@ -23,7 +23,7 @@ impl fmt::Display for ConfigError { match &self.original_error { Some(original_error) => { write!(f, "{}: \"{}\"", self.description, original_error) - }, + } None => write!(f, "{}", self.description) } } diff --git a/src/config/load.rs b/src/config/load.rs index 3c9c2d2..d508435 100644 --- a/src/config/load.rs +++ b/src/config/load.rs @@ -1,7 +1,8 @@ -use serde_yaml; use std::fs::File; use std::io::prelude::*; +use serde_yaml; + use config::error::ConfigError; use config::model::Config; @@ -23,10 +24,10 @@ pub fn read(path: &str) -> Result { } else { Result::Err(ConfigError::new("Empty Configuration File", Option::None)) } - }, + } Err(e) => Result::Err(ConfigError::new("Cannot Read Configuration File", Option::Some(Box::from(e)))) } - }, + } Err(_e) => Result::Err(ConfigError::new(&format!("Configuration File Doesn't Exist \"{}\"", path), Option::None)) } } \ No newline at end of file diff --git a/src/config/model.rs b/src/config/model.rs index 9a6a098..ec87fef 100644 --- a/src/config/model.rs +++ b/src/config/model.rs @@ -1,16 +1,15 @@ - #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct ServerConfig { pub host: Option, pub port: Option, - pub workers: Option + pub workers: Option, } #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct CloudflareDomainConfig { pub domain: String, - pub zone_id: String + pub zone_id: String, } @@ -18,14 +17,14 @@ pub struct CloudflareDomainConfig { pub struct CloudflareConfig { pub domains: Vec, pub key: String, - pub email: String + pub email: String, } #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct DDNSDomain { pub domain: String, - pub subdomains: Vec + pub subdomains: Vec, } @@ -38,14 +37,14 @@ pub struct DDNSConfig { #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct UserSubdomainConfig { pub subdomain: String, - pub targets: Vec + pub targets: Vec, } #[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct UserDomainConfig { pub domain: String, - pub subdomains: Vec + pub subdomains: Vec, } @@ -53,7 +52,7 @@ pub struct UserDomainConfig { pub struct UserConfig { pub username: String, pub token: String, - pub domains: Vec + pub domains: Vec, } @@ -62,5 +61,5 @@ pub struct Config { pub server: ServerConfig, pub cloudflare: CloudflareConfig, pub ddns: DDNSConfig, - pub users: Vec + pub users: Vec, } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a3e027d..3ba5207 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,16 @@ -#[macro_use] -extern crate serde_derive; -#[macro_use] -extern crate log; -#[macro_use] -extern crate lazy_static; - extern crate actix_web; extern crate bytes; extern crate clap; extern crate env_logger; extern crate futures; +#[macro_use] +extern crate lazy_static; +#[macro_use] +extern crate log; extern crate num_cpus; extern crate serde; +#[macro_use] +extern crate serde_derive; extern crate serde_yaml; use clap::{App, Arg}; @@ -77,7 +76,7 @@ fn main() { Ok(c) => { info!("Loaded configuration from \"{}\"", config_path); Option::Some(c) - }, + } Err(e) => { error!("{}", e); Option::None diff --git a/src/server/api.rs b/src/server/api.rs index 1dc1f6d..5c5a6ef 100644 --- a/src/server/api.rs +++ b/src/server/api.rs @@ -1,20 +1,21 @@ +use std::io::Read; + +use actix_web::{AsyncResponder, FutureResponse, HttpMessage, HttpRequest, HttpResponse, Scope}; use actix_web::http::Method; use actix_web::http::StatusCode; -use actix_web::{AsyncResponder, FutureResponse, HttpMessage, HttpRequest, HttpResponse, Scope}; use bytes::{Buf, Bytes, IntoBuf}; use futures::future::Future; -use std::io::Read; pub fn route(scope: Scope<()>) -> Scope<()> { scope.resource("address", |r| r.method(Method::GET).f(get_address)) - .nested("{root}/{zone}", |zone_scope| { - zone_scope - .resource("", |r| r.method(Method::GET).f(get_address)) - .resource("update", |r| { - r.method(Method::GET).f(update_address_automatically); - r.method(Method::POST).f(update_address_manually) - }) - }) + .nested("{root}/{zone}", |zone_scope| { + zone_scope + .resource("", |r| r.method(Method::GET).f(get_address)) + .resource("update", |r| { + r.method(Method::GET).f(update_address_automatically); + r.method(Method::POST).f(update_address_manually) + }) + }) } fn update_address(address: String) -> String { diff --git a/src/server/router.rs b/src/server/router.rs index 8ae29f3..88ac497 100644 --- a/src/server/router.rs +++ b/src/server/router.rs @@ -1,7 +1,7 @@ extern crate actix_web; +use actix_web::{App, http}; use actix_web::middleware::Logger; -use actix_web::{http, App}; use server;