load patch config from env vars
This commit is contained in:
parent
29422eac51
commit
466195193d
@ -1,10 +1,10 @@
|
||||
use elseware::patch::patch::{PatchServerState, generate_patch_tree, load_config, load_motd};
|
||||
use elseware::patch::patch::{PatchServerState, generate_patch_tree, load_config_env, load_motd};
|
||||
use log::{info};
|
||||
use elseware::common::mainloop::patch_mainloop;
|
||||
|
||||
fn main() {
|
||||
info!("[patch] starting server");
|
||||
let patch_config = load_config();
|
||||
let patch_config = load_config_env();
|
||||
let patch_motd = load_motd();
|
||||
let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str());
|
||||
let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd);
|
||||
|
@ -381,7 +381,7 @@ impl Iterator for SendFileIterator {
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct PatchConfig {
|
||||
pub path: String,
|
||||
pub ip: String,
|
||||
pub ip: String, // TODO: this does nothing
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
@ -403,11 +403,22 @@ pub fn load_config() -> PatchConfig {
|
||||
config
|
||||
}
|
||||
|
||||
pub fn load_motd() -> String {
|
||||
let mut motd: String = "Welcome to Elseware!".to_string();
|
||||
pub fn load_config_env() -> PatchConfig {
|
||||
let patch_path = std::env::var("PATCHFILE_DIR").unwrap();
|
||||
let patch_port = std::env::var("PATCH_PORT").unwrap().parse().unwrap();
|
||||
|
||||
if let Ok(m) = fs::read_to_string("patch.motd") {
|
||||
motd = m.clone();
|
||||
PatchConfig {
|
||||
path: patch_path,
|
||||
ip: "127.0.0.1".into(),
|
||||
port: patch_port,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_motd() -> String {
|
||||
if let Ok(m) = fs::read_to_string("patch.motd") {
|
||||
m
|
||||
}
|
||||
else {
|
||||
"Welcome to Elseware!".to_string()
|
||||
}
|
||||
motd
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user