polykit_cache/
config.rs

1//! Server configuration.
2
3use std::path::PathBuf;
4
5/// Server configuration.
6#[derive(Debug, Clone)]
7pub struct ServerConfig {
8    /// Storage directory for artifacts.
9    pub storage_dir: PathBuf,
10    /// Maximum artifact size in bytes.
11    pub max_artifact_size: u64,
12    /// Bind address.
13    pub bind_address: String,
14    /// Port number.
15    pub port: u16,
16}
17
18impl Default for ServerConfig {
19    fn default() -> Self {
20        Self {
21            storage_dir: PathBuf::from("./cache"),
22            max_artifact_size: 1024 * 1024 * 1024, // 1GB
23            bind_address: "127.0.0.1".to_string(),
24            port: 8080,
25        }
26    }
27}
28
29impl ServerConfig {
30    /// Creates a new server configuration.
31    pub fn new() -> Self {
32        Self::default()
33    }
34
35    /// Sets the storage directory.
36    pub fn with_storage_dir(mut self, dir: impl Into<PathBuf>) -> Self {
37        self.storage_dir = dir.into();
38        self
39    }
40
41    /// Sets the maximum artifact size.
42    pub fn with_max_artifact_size(mut self, size: u64) -> Self {
43        self.max_artifact_size = size;
44        self
45    }
46
47    /// Sets the bind address.
48    pub fn with_bind_address(mut self, address: impl Into<String>) -> Self {
49        self.bind_address = address.into();
50        self
51    }
52
53    /// Sets the port.
54    pub fn with_port(mut self, port: u16) -> Self {
55        self.port = port;
56        self
57    }
58
59    /// Returns the bind address as a string.
60    pub fn bind_addr(&self) -> String {
61        format!("{}:{}", self.bind_address, self.port)
62    }
63}