rs-zero 0.1.1

Rust-first microservice framework inspired by go-zero engineering practices
Documentation
use std::time::Duration;

/// JWT authorization configuration.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AuthConfig {
    /// HS256 secret used to validate bearer tokens.
    pub secret: String,
    /// Exact request paths that bypass token validation.
    pub public_paths: Vec<String>,
}

impl AuthConfig {
    /// Returns whether `path` is public.
    pub fn is_public(&self, path: &str) -> bool {
        self.public_paths.iter().any(|item| item == path)
    }
}

/// REST service runtime configuration.
#[derive(Debug, Clone)]
pub struct RestConfig {
    /// Service name used by logs and traces.
    pub name: String,
    /// Request timeout.
    pub timeout: Duration,
    /// Maximum accepted request body size.
    pub max_body_bytes: usize,
    /// Optional JWT authorization configuration.
    pub auth: Option<AuthConfig>,
}

impl Default for RestConfig {
    fn default() -> Self {
        Self {
            name: "rs-zero".to_string(),
            timeout: Duration::from_secs(5),
            max_body_bytes: 1024 * 1024,
            auth: None,
        }
    }
}