-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_helper.rs
44 lines (41 loc) · 1.43 KB
/
config_helper.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::data::config::entity::config_file::Config;
use std::fs::File;
use std::io::BufReader;
pub fn get_config() -> anyhow::Result<Config> {
let file = File::open("./config/config.json").expect("Unable to open config file.");
let config = BufReader::new(file);
let mut config: Config = serde_json::from_reader(config).expect("Unable to read json");
for (key, value) in std::env::vars() {
match key.as_str() {
"DATABASE_URL" => {
config.database_url = value;
}
"NUMBER_CAN_RETRIES" => {
config.number_can_retries = value.parse()?;
}
"REQUEST_CONCURRENCY_COUNT" => {
config.request_concurrency_count = value.parse()?;
}
"HTTP_ADDRESS" => {
config.http_config.http_address = value;
}
"HTTP_PORT" => {
config.http_config.http_port = value.parse()?;
}
"HTTPS_ADDRESS" => {
config.http_config.https_address = value;
}
"HTTPS_PORT" => {
config.http_config.https_port = value.parse()?;
}
"TLS_CERT_PATH" => {
config.http_config.tls_cert_path = value.parse()?;
}
"TLS_KEY_PATH" => {
config.http_config.tls_key_path = value.parse()?;
}
_ => {}
}
}
Ok(config)
}