Provide option to set config file location by env

This commit is contained in:
Edward Shen 2019-05-02 00:02:53 -04:00
parent 5aa57864d7
commit 978321b0ce
Signed by: edward
GPG key ID: F350507060ED6C90

View file

@ -19,6 +19,7 @@ use actix_web::{middleware::Logger, web::resource, App, HttpServer};
use chrono::prelude::*; use chrono::prelude::*;
use ron::de::from_str; use ron::de::from_str;
use std::{ use std::{
env::var,
fs::read_to_string, fs::read_to_string,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
time::Duration, time::Duration,
@ -32,8 +33,10 @@ pub type State = Arc<RwLock<QueryResults>>;
fn main() { fn main() {
System::run(move || { System::run(move || {
let conf_file_loc =
var("ENDSTAT_CONF").unwrap_or_else(|_| String::from("./endstat_conf.ron"));
let config = from_str::<Config>( let config = from_str::<Config>(
&read_to_string("./endstat_conf.ron").expect("finding ./endstat_conf.ron"), &read_to_string(&conf_file_loc).expect(&format!("finding {}", conf_file_loc)),
) )
.unwrap(); .unwrap();
let bind_addr = config.bind_address.clone(); let bind_addr = config.bind_address.clone();