Skip to main content

koi_embedded/
config.rs

1use std::net::IpAddr;
2use std::path::PathBuf;
3
4use koi_dns::DnsConfig;
5
6#[derive(Debug, Clone)]
7pub struct KoiConfig {
8    pub data_dir: Option<PathBuf>,
9    pub service_endpoint: String,
10    pub service_mode: ServiceMode,
11    pub http_enabled: bool,
12    pub mdns_enabled: bool,
13    pub dns_enabled: bool,
14    pub health_enabled: bool,
15    pub certmesh_enabled: bool,
16    pub proxy_enabled: bool,
17    pub dns_config: DnsConfig,
18    pub dns_auto_start: bool,
19    pub health_auto_start: bool,
20    pub proxy_auto_start: bool,
21}
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum ServiceMode {
25    Auto,
26    EmbeddedOnly,
27    ClientOnly,
28}
29
30impl Default for KoiConfig {
31    fn default() -> Self {
32        Self {
33            data_dir: None,
34            service_endpoint: "http://127.0.0.1:5641".to_string(),
35            service_mode: ServiceMode::Auto,
36            http_enabled: false,
37            mdns_enabled: true,
38            dns_enabled: true,
39            health_enabled: false,
40            certmesh_enabled: false,
41            proxy_enabled: false,
42            dns_config: DnsConfig::default(),
43            dns_auto_start: false,
44            health_auto_start: false,
45            proxy_auto_start: false,
46        }
47    }
48}
49
50pub struct DnsConfigBuilder {
51    config: DnsConfig,
52}
53
54impl DnsConfigBuilder {
55    pub fn new(config: DnsConfig) -> Self {
56        Self { config }
57    }
58
59    pub fn bind_addr(mut self, addr: IpAddr) -> Self {
60        self.config.bind_addr = addr;
61        self
62    }
63
64    pub fn port(mut self, port: u16) -> Self {
65        self.config.port = port;
66        self
67    }
68
69    pub fn zone(mut self, zone: impl Into<String>) -> Self {
70        self.config.zone = zone.into();
71        self
72    }
73
74    pub fn local_ttl(mut self, ttl: u32) -> Self {
75        self.config.local_ttl = ttl;
76        self
77    }
78
79    pub fn allow_public_clients(mut self, allow: bool) -> Self {
80        self.config.allow_public_clients = allow;
81        self
82    }
83
84    pub fn max_qps(mut self, max_qps: u32) -> Self {
85        self.config.max_qps = max_qps;
86        self
87    }
88
89    pub fn build(self) -> DnsConfig {
90        self.config
91    }
92}