Mercurial > templog
annotate rust/src/config.rs @ 634:a5721c02d3ee rust
build succeeds
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 22 Sep 2019 20:35:40 +0800 |
parents | f3e39e2107fd |
children | 4424a8b30f9c |
rev | line source |
---|---|
634 | 1 use serde::{Serialize,Deserialize}; |
595 | 2 |
634 | 3 use super::types::*; |
611
f3e39e2107fd
still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents:
601
diff
changeset
|
4 |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
5 #[derive(Deserialize,Serialize,Debug,Clone)] |
595 | 6 #[allow(non_snake_case)] |
7 pub struct Config { | |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
8 pub SENSOR_SLEEP: u64, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
9 pub UPLOAD_SLEEP: u64, |
595 | 10 |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
11 pub FRIDGE_DELAY: u64, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
12 pub FRIDGE_WORT_INVALID_TIME: u64, |
595 | 13 |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
14 pub MAX_READINGS: u32, |
595 | 15 |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
16 pub PARAMS_FILE: String, |
595 | 17 |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
18 pub SENSOR_BASE_DIR: String, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
19 pub FRIDGE_GPIO_PIN: u32, |
595 | 20 |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
21 pub AMBIENT_NAME: String, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
22 pub FRIDGE_NAME: String, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
23 pub WORT_NAME: String, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
24 pub INTERNAL_TEMPERATURE: String, |
595 | 25 |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
26 pub HMAC_KEY: String, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
27 pub SERVER_URL: String, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
28 pub UPDATE_URL: String, |
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
29 pub SETTINGS_URL: String, |
595 | 30 } |
31 | |
32 impl Config { | |
634 | 33 pub fn default_toml() -> &'static str { |
34 include_str!("defconfig.toml") | |
595 | 35 } |
36 | |
634 | 37 pub fn load() -> Result<Self, TemplogError> { |
38 let mut c = config::Config::default(); | |
39 c.merge(config::File::from_str(Self::default_toml(), config::FileFormat::Toml)); | |
40 c.merge(config::File::with_name("local.conf")).unwrap(); | |
41 c.merge(config::Environment::with_prefix("TEMPLOG")).unwrap(); | |
42 Ok(c.try_into().unwrap()) | |
597 | 43 } |
595 | 44 } |