Skip to content

Commit

Permalink
Add ServerConf::merge_with_opt for when Opt/ServerConf are used together
Browse files Browse the repository at this point in the history
  • Loading branch information
drcaramelsyrup committed Mar 30, 2024
1 parent 414b0f0 commit ff6f0bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 8 additions & 6 deletions pingora-core/src/server/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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)]
Expand Down
4 changes: 3 additions & 1 deletion pingora-core/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ff6f0bb

Please sign in to comment.