summaryrefslogtreecommitdiff
path: root/taler-config/src/lib.rs
blob: fb7af71a3789d3e335d2c1cf7d62597dc4133c66 (plain)
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
use std::path::Path;
use url::Url;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Config {
    pub base_url: Url,
    pub db_url: String,
    pub port: u16,
    pub payto: Url,
    pub address: String,
    pub confirmation: u8,
}

impl Config {
    pub fn from_path(path: impl AsRef<Path>) -> Self {
        let conf = ini::Ini::load_from_file(path).unwrap();
        let conf = conf.section(Some("main")).unwrap();
        Self {
            base_url: Url::parse(&conf.get("BASE_URL").unwrap()).unwrap(),
            db_url: conf.get("DB_URL").unwrap().to_string(),
            port: conf.get("PORT").unwrap().parse().unwrap(),
            payto: Url::parse(&conf.get("PAYTO").unwrap()).unwrap(),
            address: conf.get("ADDRESS").unwrap().to_string(),
            confirmation: conf.get("CONFIRMATION").unwrap().parse().unwrap(),
        }
    }
}