feature/upstream-service #13
@@ -13,6 +13,8 @@ use crate::{
|
|||||||
set_if_some,
|
set_if_some,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const PLACEHOLDER_TARGET: &str = "server 127.0.0.1:65535 down; # placeholder target\n";
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct UpstreamInfo {
|
pub struct UpstreamInfo {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
@@ -54,12 +56,18 @@ impl NginxConfigProvider for UpstreamInfo {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|target| target.to_nginx_config(Some(indent.unwrap_or(0) + INDENT_SIZE)))
|
.map(|target| target.to_nginx_config(Some(indent.unwrap_or(0) + INDENT_SIZE)))
|
||||||
.collect();
|
.collect();
|
||||||
let targets_config_str = if targets_config.is_empty() {
|
let mut targets_config_str = if targets_config.is_empty() {
|
||||||
"server 127.0.0.1:65535 down; # placeholder target".to_string()
|
PLACEHOLDER_TARGET.to_string()
|
||||||
} else {
|
} else {
|
||||||
targets_config.join("\n")
|
let mut r = targets_config.join("\n");
|
||||||
|
r.push('\n');
|
||||||
|
r
|
||||||
}
|
}
|
||||||
.indent(indent.unwrap_or(0) + INDENT_SIZE);
|
.indent(indent.unwrap_or(0) + INDENT_SIZE);
|
||||||
|
if self.upstream_targets.iter().all(|v| v.is_backup) {
|
||||||
|
targets_config_str
|
||||||
|
.push_str(&PLACEHOLDER_TARGET.indent(indent.unwrap_or(0) + INDENT_SIZE));
|
||||||
|
}
|
||||||
format!("upstream {} {{\n{}\n}}", self.name, targets_config_str).indent(indent.unwrap_or(0))
|
format!("upstream {} {{\n{}\n}}", self.name, targets_config_str).indent(indent.unwrap_or(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,6 +114,17 @@ impl From<upstream::Model> for UpstreamInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<(upstream::Model, Option<Vec<upstream_target::Model>>)> for UpstreamInfo {
|
||||||
|
fn from(data: (upstream::Model, Option<Vec<upstream_target::Model>>)) -> Self {
|
||||||
|
let (upstream_model, upstream_target_models) = data;
|
||||||
|
if let Some(targets) = upstream_target_models {
|
||||||
|
UpstreamInfo::from((upstream_model, targets))
|
||||||
|
} else {
|
||||||
|
UpstreamInfo::from(upstream_model)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<(upstream::Model, Vec<upstream_target::Model>)> for UpstreamInfo {
|
impl From<(upstream::Model, Vec<upstream_target::Model>)> for UpstreamInfo {
|
||||||
fn from(data: (upstream::Model, Vec<upstream_target::Model>)) -> Self {
|
fn from(data: (upstream::Model, Vec<upstream_target::Model>)) -> Self {
|
||||||
let (upstream_model, upstream_target_models) = data;
|
let (upstream_model, upstream_target_models) = data;
|
||||||
|
|||||||
Reference in New Issue
Block a user