| 846 | } |
| 847 | |
| 848 | pub fn load(config_dir: &Path) -> Result<()> { |
| 849 | let mut content: String = String::new(); |
| 850 | |
| 851 | let paths = fs::read_dir(config_dir)?; |
| 852 | for path in paths { |
| 853 | let path = path.unwrap().path(); |
| 854 | |
| 855 | if let Some(ext) = path.extension() |
| 856 | && ext == "toml" |
| 857 | { |
| 858 | content.push_str( |
| 859 | &fs::read_to_string(&path) |
| 860 | .context(format!("Read config file: {}", path.display()))?, |
| 861 | ); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | // substitute environment variables in config file |
| 866 | for (k, v) in env::vars() { |
| 867 | content = content.replace(&format!("${}", k), &v); |
| 868 | } |
| 869 | |
| 870 | let mut conf: Configuration = toml::from_str(&content)?; |
| 871 | |
| 872 | // Backfill extra-channel data-rates. |
| 873 | for region in &mut conf.regions { |
| 874 | for extra_channel in &mut region.network.extra_channels { |
| 875 | if !extra_channel.data_rates.is_empty() { |
| 876 | continue; |
| 877 | } |
| 878 | |
| 879 | warn!( |
| 880 | region = region.id, |
| 881 | "Using min_dr / max_dr for extra-channel configuration is deprecated, use data_rates instead!" |
| 882 | ); |
| 883 | |
| 884 | extra_channel |
| 885 | .data_rates |
| 886 | .extend(extra_channel.min_dr..=extra_channel.max_dr); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | set(conf); |
| 891 | |
| 892 | Ok(()) |
| 893 | } |
| 894 | |
| 895 | pub fn set(c: Configuration) { |
| 896 | let mut conf_mutex = CONFIG.lock().unwrap(); |