use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct GatewayConfig {
pub database_url: String,
pub schema_path: String,
pub policy_path: Option<String>,
pub bind_address: String,
pub cors_enabled: bool,
}
impl Default for GatewayConfig {
fn default() -> Self {
Self {
database_url: "postgres://localhost/qail".to_string(),
schema_path: "schema.qail".to_string(),
policy_path: None,
bind_address: "0.0.0.0:8080".to_string(),
cors_enabled: true,
}
}
}
impl GatewayConfig {
pub fn builder() -> GatewayConfigBuilder {
GatewayConfigBuilder::default()
}
}
#[derive(Debug, Default)]
pub struct GatewayConfigBuilder {
config: GatewayConfig,
}
impl GatewayConfigBuilder {
pub fn database(mut self, url: impl Into<String>) -> Self {
self.config.database_url = url.into();
self
}
pub fn schema(mut self, path: impl Into<String>) -> Self {
self.config.schema_path = path.into();
self
}
pub fn policy(mut self, path: impl Into<String>) -> Self {
self.config.policy_path = Some(path.into());
self
}
pub fn bind(mut self, addr: impl Into<String>) -> Self {
self.config.bind_address = addr.into();
self
}
pub fn build(self) -> GatewayConfig {
self.config
}
}