-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from AssetsArt/fest-config
Fest config
- Loading branch information
Showing
19 changed files
with
1,140 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,2 @@ | ||
pub mod models; | ||
pub mod proxy; | ||
|
||
// use | ||
use std::sync::Once; | ||
use std::{fs::File, io::BufReader}; | ||
|
||
// This is a global variable that is initialized once | ||
static INIT_CONFIG: Once = Once::new(); | ||
static mut GLOBAL_CONFIG: *const models::AppConfig = std::ptr::null(); | ||
|
||
pub fn app_config() -> &'static models::AppConfig { | ||
INIT_CONFIG.call_once(|| { | ||
// FROM ENV | ||
let conf_path = std::env::var("EASY_PROXY_CONF"); | ||
let conf_path = match conf_path { | ||
Ok(val) => val, | ||
Err(_e) => { | ||
let conf_path = std::env::current_dir().expect("Unable to get current dir"); | ||
conf_path | ||
.join(".config/easy_proxy.yaml") | ||
.to_str() | ||
.expect("Unable to convert path") | ||
.to_string() | ||
} | ||
}; | ||
|
||
let open_conf = File::open(conf_path).expect("Unable to open file"); | ||
let read_conf = BufReader::new(open_conf); | ||
let conf: models::AppConfig = | ||
serde_yaml::from_reader(read_conf).expect("Unable to read conf file"); | ||
|
||
unsafe { | ||
GLOBAL_CONFIG = Box::into_raw(Box::new(conf)); | ||
} | ||
}); | ||
|
||
unsafe { &*GLOBAL_CONFIG } | ||
} | ||
pub mod runtime; |
Oops, something went wrong.