forked from mateusfreira/nun-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.rs
43 lines (39 loc) · 1.49 KB
/
configuration.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
use std::env;
#[derive(Debug)]
pub struct Configuration {
pub nun_user: String,
pub nun_pwd: String,
pub nun_dbs_dir: String,
pub nun_ws_addr: String,
pub nun_http_addr: String,
pub nun_tcp_addr: String,
pub nun_replicate_addr: String,
pub nun_log_level: String,
pub nun_log_dir: String,
pub nun_log_to_file: String,
}
#[cfg(debug_assertions)]
fn expect_env_var(name: &str, default: &str) -> String {
return env::var(name).unwrap_or(String::from(default));
}
#[cfg(not(debug_assertions))]
fn expect_env_var(name: &str, _default: &str) -> String {
return env::var(name).expect(&format!(
"Environment variable {name} is not defined",
name = name
));
}
pub fn get_configuration() -> Configuration {
Configuration {
nun_user: expect_env_var("NUN_USER", "mateus"),
nun_pwd: expect_env_var("NUN_PWD", "mateus"),
nun_dbs_dir: expect_env_var("NUN_DBS_DIR", "/tmp/data/nun_db"),
nun_ws_addr: expect_env_var("NUN_WS_ADDR", "0.0.0.0:3012"),
nun_http_addr: expect_env_var("NUN_HTTP_ADDR", "0.0.0.0:3013"),
nun_tcp_addr: expect_env_var("NUN_HTTP_ADDR", "0.0.0.0:3014"),
nun_replicate_addr: expect_env_var("NUN_REPLICATE_ADDR", ""),
nun_log_level: expect_env_var("NUN_LOG_LEVEL", "Info"), //(Off, Error, Warn, Info, Debug, Trace)
nun_log_dir: expect_env_var("NUN_LOG_DIR", "/tmp/data/nun_db/log"),
nun_log_to_file: expect_env_var("NUN_LOG_TO_FILE", "true"), //true or false
}
}