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
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use actix_identity::IdentityMiddleware;
|
use actix_identity::IdentityMiddleware;
|
||||||
|
@ -11,14 +10,15 @@ use actix_web::{cookie::Key, middleware, App, HttpServer};
|
||||||
use db::migrate::RunMigrations;
|
use db::migrate::RunMigrations;
|
||||||
|
|
||||||
mod billing;
|
mod billing;
|
||||||
|
mod db;
|
||||||
mod identity;
|
mod identity;
|
||||||
mod inventory;
|
mod inventory;
|
||||||
mod ordering;
|
mod ordering;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod db;
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let settings = settings::Settings::new().unwrap();
|
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 secret_key = Key::from(settings.server.cookie_secret.as_bytes());
|
||||||
|
|
||||||
let socket_addr = settings.server.get_ip();
|
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 || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(IdentityMiddleware::default())
|
.wrap(IdentityMiddleware::default())
|
||||||
|
@ -53,7 +57,7 @@ async fn main() {
|
||||||
.wrap(
|
.wrap(
|
||||||
middleware::DefaultHeaders::new().add(("Permissions-Policy", "interest-cohort=()")),
|
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())
|
.configure(utils::random_string::GenerateRandomString::inject())
|
||||||
})
|
})
|
||||||
.bind(&socket_addr)
|
.bind(&socket_addr)
|
||||||
|
@ -62,4 +66,3 @@ async fn main() {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,12 @@ use std::sync::Arc;
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
use mockall::predicate::*;
|
use mockall::predicate::*;
|
||||||
use mockall::*;
|
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]
|
#[automock]
|
||||||
pub trait GenerateRandomStringInterface: Send + Sync {
|
pub trait GenerateRandomStringInterface: Send + Sync {
|
||||||
|
@ -34,7 +38,7 @@ impl GenerateRandomStringInterface for GenerateRandomString {
|
||||||
|
|
||||||
impl GenerateRandomString {
|
impl GenerateRandomString {
|
||||||
pub fn inject() -> impl FnOnce(&mut web::ServiceConfig) {
|
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| {
|
let f = move |cfg: &mut web::ServiceConfig| {
|
||||||
cfg.app_data(g);
|
cfg.app_data(g);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue