reifydb_sub_server/config/
server.rs1use super::{NetworkConfig, ProtocolConfigs};
5
6#[derive(Debug, Clone)]
8pub struct ServerConfig {
9 pub bind_addr: String,
11 pub network: NetworkConfig,
13 pub protocols: ProtocolConfigs,
15}
16
17impl ServerConfig {
18 pub fn new() -> Self {
20 Self::default()
21 }
22
23 pub fn bind_addr<S: Into<String>>(mut self, addr: S) -> Self {
25 self.bind_addr = addr.into();
26 self
27 }
28
29 pub fn network(mut self, config: NetworkConfig) -> Self {
31 self.network = config;
32 self
33 }
34
35 pub fn protocols(mut self, config: ProtocolConfigs) -> Self {
37 self.protocols = config;
38 self
39 }
40
41 pub fn enable_websocket(mut self, config: Option<super::WebSocketConfig>) -> Self {
43 self.protocols.ws = config.or_else(|| Some(Default::default()));
44 self
45 }
46
47 pub fn enable_http(mut self, config: Option<super::HttpConfig>) -> Self {
49 self.protocols.http = config.or_else(|| Some(Default::default()));
50 self
51 }
52
53 pub fn effective_listeners(&self) -> usize {
55 self.network.listeners.unwrap_or(1)
56 }
57}
58
59impl Default for ServerConfig {
60 fn default() -> Self {
61 Self {
62 bind_addr: "0.0.0.0:8090".to_string(),
63 network: NetworkConfig::default(),
64 protocols: ProtocolConfigs::default(),
65 }
66 }
67}