Skip to content

Commit

Permalink
Tried to simplify usage #13
Browse files Browse the repository at this point in the history
  • Loading branch information
serayuzgur committed Apr 18, 2017
1 parent 1112758 commit fc01df2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ extern crate serde_json;
use std::fs::File;
use std::io::prelude::*;
use weld;
use std::path::Path;


#[derive(Serialize, Deserialize)]
#[derive(Debug,Clone)]
Expand All @@ -12,7 +14,7 @@ pub struct Configuration {
}

impl Configuration {
pub fn new(path: &String) -> Configuration {
pub fn new (path: &str) -> Configuration {
if path != "" {
info!(weld::ROOT_LOGGER, "Configuration - Reading Path: {:?}", &path);
let mut file = File::open(path).expect("Configuration - Error Can't read provided configuration. Terminating...");
Expand Down Expand Up @@ -41,7 +43,7 @@ impl Configuration {
};
}
}
pub fn load(&mut self, path: &String) {
pub fn load(&mut self, path: &str) {
let configuration = Configuration::new(&path);
self.server = configuration.server;
self.database = configuration.database;
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub mod weld {

lazy_static! {
pub static ref ROOT_LOGGER: slog::Logger = slog::Logger::root(Arc::new(slog_async::Async::new(slog_term::CompactFormat::new(slog_term::TermDecorator::new().build()).build().fuse()).build().fuse()), o!());
pub static ref CONFIGURATION : Mutex<Configuration> = Mutex::new(Configuration::new(&"".to_string()));
pub static ref CONFIGURATION : Mutex<Configuration> = Mutex::new(Configuration::new(""));
pub static ref DATABASE : Mutex<Database> = Mutex::new(Database::new(&configuration::Database{path:"".to_string()}));
}
}
Expand All @@ -56,10 +56,10 @@ fn main() {
info!(weld::ROOT_LOGGER, "Application started";"started_at" => format!("{}", time::now().rfc3339()), "version" => env!("CARGO_PKG_VERSION"));
let mut configuration = weld::CONFIGURATION.lock().unwrap();
match args().nth(1) {
Some(path) => configuration.load(&path.to_string()),
Some(path) => configuration.load(path.as_str()),
None => {
info!(weld::ROOT_LOGGER,"Program arguments not found.");
configuration.load(&"weld.json".to_string());
configuration.load("weld.json");
}
}
load_db(&configuration);
Expand Down

0 comments on commit fc01df2

Please sign in to comment.