-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs.txt
52 lines (46 loc) · 1.39 KB
/
build.rs.txt
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
45
46
47
48
49
50
51
52
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate json_config;
use json_config::ConfigurationBuilder;
use json_config::ConfigurationSource;
use json_config::ConfigurationDefinitionParams;
pub fn main(){
let base_config_str = r#"
{
"appName": "json_config Demo",
"appVersion": 1.5,
"database": {
"host": "dev.database.com",
"port": 3000
}
}"#;
let mut builder = config!(vec![
from_str!(base_config_str),
from_file!("config/translations.json"),
from_file!("config/keystore.json"),
bundle!("QA", vec![
from_json!({
"database": {
"host": "qa.database.com",
"port": 3001
}
}),
from_file!("config/keystore_qa.json")
]),
bundle!("PROD",vec![
from_json!({
"database": {
"host": "prod.database.com",
"port": 3002
}
}),
from_file!("config/keystore_prod.json")
])
]);
//execute cargo build after setting the environment variable JSON_CONFIG_ENV
//i.e. set JSON_CONFIG_ENV=QA on Windows
//i.e. export JSON_CONFIG_ENV=QA on Linux/MacOS
builder.merge_bundle(env!("JSON_CONFIG_ENV"));
builder.to_compiled("json_config.json");
}