use std::path::PathBuf;
#[derive(Debug, Clone, Default)]
pub enum TransportMode {
#[default]
TcpWithFallback,
Tcp {
port: u16,
},
#[cfg(unix)]
UnixSocket {
path: PathBuf,
},
Grpc {
port: u16,
},
}
#[derive(Debug, Clone)]
pub struct ServerConfig {
pub transport: TransportMode,
pub instance_name: String,
pub default_session_name: String,
}
impl Default for ServerConfig {
fn default() -> Self {
Self {
transport: TransportMode::TcpWithFallback,
instance_name: String::from("default"),
default_session_name: String::from("default"),
}
}
}
impl ServerConfig {
#[must_use]
pub fn grpc(port: u16) -> Self {
Self {
transport: TransportMode::Grpc { port },
..Self::default()
}
}
#[must_use]
pub fn tcp(port: u16) -> Self {
Self {
transport: TransportMode::Tcp { port },
..Self::default()
}
}
#[cfg(unix)]
#[must_use]
pub fn unix_socket(path: impl Into<PathBuf>) -> Self {
Self {
transport: TransportMode::UnixSocket { path: path.into() },
..Self::default()
}
}
#[must_use]
pub fn with_instance_name(mut self, name: impl Into<String>) -> Self {
self.instance_name = name.into();
self
}
#[must_use]
pub fn with_session_name(mut self, name: impl Into<String>) -> Self {
self.default_session_name = name.into();
self
}
}
#[cfg(test)]
#[path = "config_tests.rs"]
mod tests;