use std::path::PathBuf;
#[derive(Debug, Clone)]
pub struct ServerConfig {
pub storage_dir: PathBuf,
pub max_artifact_size: u64,
pub bind_address: String,
pub port: u16,
}
impl Default for ServerConfig {
fn default() -> Self {
Self {
storage_dir: PathBuf::from("./cache"),
max_artifact_size: 1024 * 1024 * 1024, bind_address: "127.0.0.1".to_string(),
port: 8080,
}
}
}
impl ServerConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_storage_dir(mut self, dir: impl Into<PathBuf>) -> Self {
self.storage_dir = dir.into();
self
}
pub fn with_max_artifact_size(mut self, size: u64) -> Self {
self.max_artifact_size = size;
self
}
pub fn with_bind_address(mut self, address: impl Into<String>) -> Self {
self.bind_address = address.into();
self
}
pub fn with_port(mut self, port: u16) -> Self {
self.port = port;
self
}
pub fn bind_addr(&self) -> String {
format!("{}:{}", self.bind_address, self.port)
}
}