mirror of
https://github.com/girlbossceo/conduwuit.git
synced 2024-11-27 11:45:23 +00:00
add formal wrapping for api state
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
5c258f41c8
commit
ccef1a4c8b
|
@ -10,8 +10,8 @@ extern crate conduit_service as service;
|
|||
pub(crate) use conduit::{debug_info, pdu::PduEvent, utils, Error, Result};
|
||||
pub(crate) use service::services;
|
||||
|
||||
pub use crate::router::State;
|
||||
pub(crate) use crate::router::{Ruma, RumaResponse};
|
||||
pub use self::router::State;
|
||||
pub(crate) use self::router::{Ruma, RumaResponse};
|
||||
|
||||
conduit::mod_ctor! {}
|
||||
conduit::mod_dtor! {}
|
||||
|
|
|
@ -3,8 +3,7 @@ mod auth;
|
|||
mod handler;
|
||||
mod request;
|
||||
mod response;
|
||||
|
||||
use std::sync::Arc;
|
||||
mod state;
|
||||
|
||||
use axum::{
|
||||
response::IntoResponse,
|
||||
|
@ -15,11 +14,10 @@ use conduit::{err, Server};
|
|||
use http::Uri;
|
||||
|
||||
use self::handler::RouterExt;
|
||||
pub use self::state::State;
|
||||
pub(super) use self::{args::Args as Ruma, response::RumaResponse};
|
||||
use crate::{client, server};
|
||||
|
||||
pub type State = Arc<service::Services>;
|
||||
|
||||
pub fn build(router: Router<State>, server: &Server) -> Router<State> {
|
||||
let config = &server.config;
|
||||
let router = router
|
||||
|
|
22
src/api/router/state.rs
Normal file
22
src/api/router/state.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use std::{ops::Deref, sync::Arc};
|
||||
|
||||
use conduit_service::Services;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct State {
|
||||
services: Arc<Services>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new(services: Arc<Services>) -> Self {
|
||||
Self {
|
||||
services,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for State {
|
||||
type Target = Arc<Services>;
|
||||
|
||||
fn deref(&self) -> &Self::Target { &self.services }
|
||||
}
|
|
@ -9,7 +9,7 @@ use ruma::api::client::error::ErrorKind;
|
|||
|
||||
pub(crate) fn build(services: &Arc<Services>) -> Router {
|
||||
let router = Router::<State>::new();
|
||||
let state = services.clone();
|
||||
let state = State::new(services.clone());
|
||||
|
||||
conduit_api::router::build(router, &services.server)
|
||||
.route("/", get(it_works))
|
||||
|
|
Loading…
Reference in a new issue