Reintroduce L4P_CONFIG environment variable
This points to a user-configured configuration file. Closes #5. Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
parent
6284870059
commit
4592c94586
@ -1,6 +1,6 @@
|
||||
use crate::upstreams::ProxyToUpstream;
|
||||
use crate::upstreams::Upstream;
|
||||
use log::{debug, warn};
|
||||
use log::{debug, info, warn};
|
||||
use serde::Deserialize;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs::File;
|
||||
@ -119,9 +119,10 @@ fn load_config(path: &str) -> Result<ParsedConfigV1, ConfigError> {
|
||||
if !log_level.eq("disable") {
|
||||
std::env::set_var("FOURTH_LOG", log_level.clone());
|
||||
pretty_env_logger::init_custom_env("FOURTH_LOG");
|
||||
debug!("Set log level to {}", log_level);
|
||||
}
|
||||
|
||||
info!("Using config file: {}", &path);
|
||||
debug!("Set log level to {}", log_level);
|
||||
debug!("Config version {}", base.version);
|
||||
|
||||
let mut parsed_upstream: HashMap<String, Upstream> = HashMap::new();
|
||||
|
30
src/main.rs
30
src/main.rs
@ -5,7 +5,7 @@ mod upstreams;
|
||||
use crate::config::ConfigV1;
|
||||
use crate::servers::Server;
|
||||
|
||||
use log::{debug, error};
|
||||
use log::{debug, error, info};
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
@ -37,20 +37,28 @@ fn main() {
|
||||
}
|
||||
|
||||
fn find_config() -> Result<String, Vec<String>> {
|
||||
let possible_paths = ["/etc/l4p", ""];
|
||||
let possible_locations = ["/etc/l4p", ""];
|
||||
let possible_names = ["l4p.yaml", "config.yaml"];
|
||||
|
||||
let mut tried_paths = Vec::<String>::new();
|
||||
let mut possible_paths = Vec::<PathBuf>::new();
|
||||
|
||||
for path in possible_paths
|
||||
.iter()
|
||||
.flat_map(|&path| {
|
||||
possible_names
|
||||
.iter()
|
||||
.map(move |&file| PathBuf::new().join(path).join(file))
|
||||
})
|
||||
.collect::<Vec<PathBuf>>()
|
||||
{
|
||||
if let Ok(env_path) = std::env::var("L4P_CONFIG") {
|
||||
possible_paths.push(PathBuf::from(env_path));
|
||||
}
|
||||
|
||||
possible_paths.append(
|
||||
&mut possible_locations
|
||||
.iter()
|
||||
.flat_map(|&path| {
|
||||
possible_names
|
||||
.iter()
|
||||
.map(move |&file| PathBuf::new().join(path).join(file))
|
||||
})
|
||||
.collect::<Vec<PathBuf>>(),
|
||||
);
|
||||
|
||||
for path in possible_paths {
|
||||
let path_str = path.to_string_lossy().to_string();
|
||||
if path.exists() {
|
||||
return Ok(path_str);
|
||||
|
Loading…
Reference in New Issue
Block a user