use axum::Router;
use crate::rest::{RestConfig, middleware::apply_default_layers};
#[derive(Debug, Clone)]
pub struct RestLayerStack {
config: RestConfig,
}
impl RestLayerStack {
pub fn new(config: RestConfig) -> Self {
Self { config }
}
pub fn production_defaults(name: impl Into<String>) -> Self {
Self::new(RestConfig::production_defaults(name))
}
#[allow(deprecated)]
#[deprecated(note = "use production_defaults instead")]
pub fn go_zero_defaults(name: impl Into<String>) -> Self {
Self::production_defaults(name)
}
pub fn layer(&self, router: Router) -> Router {
apply_default_layers(router, self.config.clone())
}
pub fn into_layer(self) -> RestRouterLayer {
RestRouterLayer {
config: self.config,
}
}
}
#[derive(Debug, Clone)]
pub struct RestRouterLayer {
config: RestConfig,
}
impl tower::Layer<Router> for RestRouterLayer {
type Service = Router;
fn layer(&self, inner: Router) -> Self::Service {
apply_default_layers(inner, self.config.clone())
}
}