feat: implement Nginx service with upstream management and configuration generation

This commit is contained in:
GW_MC
2025-12-29 15:21:02 +08:00
parent 814f76291c
commit 238c3db92b
15 changed files with 661 additions and 1 deletions

View File

@@ -0,0 +1,47 @@
use crate::services::nginx::info::upstream::UpstreamInfo;
pub const INDENT_SIZE: usize = 2;
pub trait NginxConfigProvider {
fn to_nginx_config(&self, indent: Option<usize>) -> String;
}
pub struct NginxConfigBuilder {
upstreams: Vec<UpstreamInfo>,
}
impl NginxConfigBuilder {
pub fn new() -> Self {
Self {
upstreams: Vec::new(),
}
}
pub fn add_upstream(&mut self, upstream: UpstreamInfo) {
self.upstreams.push(upstream);
}
pub fn add_upstreams(&mut self, upstreams: Vec<UpstreamInfo>) {
for upstream in upstreams {
self.add_upstream(upstream);
}
}
}
impl NginxConfigProvider for NginxConfigBuilder {
fn to_nginx_config(&self, indent: Option<usize>) -> String {
let mut config = format!(
"# Nginx Config Generated by YANPM at {}",
chrono::Utc::now()
);
for upstream in &self.upstreams {
config.push('\n');
config.push_str(&upstream.to_nginx_config(indent));
}
// TODO: Add other sections like servers, locations, etc.
config
}
}