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 ron::de::from_str;
use std::{
env::var,
fs::read_to_string,
sync::{Arc, RwLock},
time::Duration,
@ -32,8 +33,10 @@ pub type State = Arc<RwLock<QueryResults>>;
fn main() {
System::run(move || {
let conf_file_loc =
var("ENDSTAT_CONF").unwrap_or_else(|_| String::from("./endstat_conf.ron"));
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();
let bind_addr = config.bind_address.clone();