feat: define types aliases for GenerateRandomStringInterface
This commit is contained in:
parent
eba678b6de
commit
b83112d359
2 changed files with 15 additions and 8 deletions
15
src/main.rs
15
src/main.rs
|
@ -2,7 +2,6 @@
|
|||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
|
||||
use std::env;
|
||||
|
||||
use actix_identity::IdentityMiddleware;
|
||||
|
@ -11,14 +10,15 @@ use actix_web::{cookie::Key, middleware, App, HttpServer};
|
|||
use db::migrate::RunMigrations;
|
||||
|
||||
mod billing;
|
||||
mod db;
|
||||
mod identity;
|
||||
mod inventory;
|
||||
mod ordering;
|
||||
mod settings;
|
||||
mod db;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
mod utils;
|
||||
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() {
|
||||
let settings = settings::Settings::new().unwrap();
|
||||
|
@ -39,7 +39,11 @@ async fn main() {
|
|||
let secret_key = Key::from(settings.server.cookie_secret.as_bytes());
|
||||
|
||||
let socket_addr = settings.server.get_ip();
|
||||
log::info!("Starting server at: {} {}", socket_addr, settings.server.domain);
|
||||
log::info!(
|
||||
"Starting server at: {} {}",
|
||||
socket_addr,
|
||||
settings.server.domain
|
||||
);
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(IdentityMiddleware::default())
|
||||
|
@ -53,7 +57,7 @@ async fn main() {
|
|||
.wrap(
|
||||
middleware::DefaultHeaders::new().add(("Permissions-Policy", "interest-cohort=()")),
|
||||
)
|
||||
// .configure(auth::adapter::load_adapters(db.pool.clone(), &settings))
|
||||
// .configure(auth::adapter::load_adapters(db.pool.clone(), &settings))
|
||||
.configure(utils::random_string::GenerateRandomString::inject())
|
||||
})
|
||||
.bind(&socket_addr)
|
||||
|
@ -62,4 +66,3 @@ async fn main() {
|
|||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,12 @@ use std::sync::Arc;
|
|||
use actix_web::web;
|
||||
use mockall::predicate::*;
|
||||
use mockall::*;
|
||||
#[cfg(test)]
|
||||
#[allow(unused_imports)]
|
||||
use tests::*;
|
||||
|
||||
pub type WebGenerateRandomStringInterface = web::Data<Arc<dyn GenerateRandomStringInterface>>;
|
||||
pub type GenerateRandomStringInterfaceObj = Arc<dyn GenerateRandomStringInterface>;
|
||||
pub type WebGenerateRandomStringInterfaceObj = web::Data<GenerateRandomStringInterfaceObj>;
|
||||
|
||||
#[automock]
|
||||
pub trait GenerateRandomStringInterface: Send + Sync {
|
||||
|
@ -34,7 +38,7 @@ impl GenerateRandomStringInterface for GenerateRandomString {
|
|||
|
||||
impl GenerateRandomString {
|
||||
pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) {
|
||||
let g = WebGenerateRandomStringInterface::new(Arc::new(GenerateRandomString));
|
||||
let g = WebGenerateRandomStringInterfaceObj::new(Arc::new(GenerateRandomString));
|
||||
let f = move |cfg: &mut web::ServiceConfig| {
|
||||
cfg.app_data(g);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue