view 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
line wrap: on
line source

use serde::{Serialize,Deserialize};

use super::types::*;

#[derive(Deserialize,Serialize,Debug,Clone)]
#[allow(non_snake_case)]
pub struct Config {
    pub SENSOR_SLEEP: u64,
    pub UPLOAD_SLEEP: u64,

    pub FRIDGE_DELAY: u64,
    pub FRIDGE_WORT_INVALID_TIME: u64,

    pub MAX_READINGS: u32,

    pub PARAMS_FILE: String,

    pub SENSOR_BASE_DIR: String,
    pub FRIDGE_GPIO_PIN: u32,

    pub AMBIENT_NAME: String,
    pub FRIDGE_NAME: String,
    pub WORT_NAME: String,
    pub INTERNAL_TEMPERATURE: String,

    pub HMAC_KEY: String,
    pub SERVER_URL: String,
    pub UPDATE_URL: String, 
    pub SETTINGS_URL: String,
}

impl Config {
    pub fn default_toml() -> &'static str {
        include_str!("defconfig.toml")
    }

    pub fn load() -> Result<Self, TemplogError> {
        let mut c = config::Config::default();
        c.merge(config::File::from_str(Self::default_toml(), config::FileFormat::Toml));
        c.merge(config::File::with_name("local.conf")).unwrap();
        c.merge(config::Environment::with_prefix("TEMPLOG")).unwrap();
        Ok(c.try_into().unwrap())
    }
}