mirror of
https://github.com/cloudflare/pingora.git
synced 2024-09-20 02:31:35 +02:00
Add ServerConf::merge_with_opt for when Opt/ServerConf are used together
This commit is contained in:
parent
414b0f082f
commit
ff6f0bbdf6
2 changed files with 11 additions and 7 deletions
|
@ -167,9 +167,7 @@ impl ServerConf {
|
|||
pub fn load_yaml_with_opt_override(opt: &Opt) -> Result<Self> {
|
||||
if let Some(path) = &opt.conf {
|
||||
let mut conf = Self::load_from_yaml(path)?;
|
||||
if opt.daemon {
|
||||
conf.daemon = true;
|
||||
}
|
||||
conf.merge_with_opt(opt);
|
||||
Ok(conf)
|
||||
} else {
|
||||
Error::e_explain(ReadError, "No path specified")
|
||||
|
@ -184,9 +182,7 @@ impl ServerConf {
|
|||
let conf = Self::new();
|
||||
match conf {
|
||||
Some(mut c) => {
|
||||
if opt.daemon {
|
||||
c.daemon = true;
|
||||
}
|
||||
c.merge_with_opt(opt);
|
||||
Some(c)
|
||||
}
|
||||
None => None,
|
||||
|
@ -211,6 +207,12 @@ impl ServerConf {
|
|||
// TODO: do the validation
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn merge_with_opt(&mut self, opt: &Opt) {
|
||||
if opt.daemon {
|
||||
self.daemon = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -175,10 +175,12 @@ impl Server {
|
|||
///
|
||||
/// If a configuration file path is provided as part of `opt`, it will be ignored
|
||||
/// and a warning will be logged.
|
||||
pub fn new_with_opt_and_conf(opt: Opt, conf: ServerConf) -> Server {
|
||||
pub fn new_with_opt_and_conf(opt: Opt, mut conf: ServerConf) -> Server {
|
||||
if let Some(c) = opt.conf.as_ref() {
|
||||
warn!("Ignoring command line argument using '{c}' as configuration, and using provided configuration instead.");
|
||||
}
|
||||
conf.merge_with_opt(&opt);
|
||||
|
||||
let (tx, rx) = watch::channel(false);
|
||||
|
||||
Server {
|
||||
|
|
Loading…
Reference in a new issue