Move app state to its own module
All checks were successful
Core Repos/ImageApi/pipeline/pr-master This commit looks good
All checks were successful
Core Repos/ImageApi/pipeline/pr-master This commit looks good
This commit is contained in:
33
src/state.rs
Normal file
33
src/state.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use crate::StreamActor;
|
||||
use actix::{Actor, Addr};
|
||||
use std::{env, sync::Arc};
|
||||
|
||||
pub struct AppState {
|
||||
pub stream_manager: Arc<Addr<StreamActor>>,
|
||||
pub base_path: String,
|
||||
pub thumbnail_path: String,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(
|
||||
stream_manager: Arc<Addr<StreamActor>>,
|
||||
base_path: String,
|
||||
thumbnail_path: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
stream_manager,
|
||||
base_path,
|
||||
thumbnail_path,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AppState {
|
||||
fn default() -> Self {
|
||||
Self::new(
|
||||
Arc::new(StreamActor {}.start()),
|
||||
env::var("BASE_PATH").expect("BASE_PATH was not set in the env"),
|
||||
env::var("THUMBNAILS").expect("THUMBNAILS was not set in the env"),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user