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