2023-07-11 13:41:56 +02:00
|
|
|
mod repo;
|
|
|
|
|
2023-07-13 16:39:52 +02:00
|
|
|
use axum::extract::FromRef;
|
2023-07-11 13:41:56 +02:00
|
|
|
use axum::Router;
|
2023-07-13 14:58:27 +02:00
|
|
|
use repo::RepoGroupManager;
|
2023-07-11 13:41:56 +02:00
|
|
|
use std::path::PathBuf;
|
2023-07-13 16:39:52 +02:00
|
|
|
use std::sync::{Arc, RwLock};
|
2023-07-11 13:41:56 +02:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Config {
|
|
|
|
data_dir: PathBuf,
|
|
|
|
repo_dir: PathBuf,
|
|
|
|
pkg_dir: PathBuf,
|
|
|
|
}
|
|
|
|
|
2023-07-13 14:58:27 +02:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Global {
|
|
|
|
config: Config,
|
|
|
|
repo_manager: Arc<RwLock<RepoGroupManager>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromRef<Global> for Arc<RwLock<RepoGroupManager>> {
|
|
|
|
fn from_ref(global: &Global) -> Self {
|
|
|
|
Arc::clone(&global.repo_manager)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-11 13:41:56 +02:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
let config = Config {
|
|
|
|
data_dir: "./data".into(),
|
|
|
|
repo_dir: "./data/repos".into(),
|
|
|
|
pkg_dir: "./data/pkgs".into(),
|
|
|
|
};
|
2023-07-13 22:06:37 +02:00
|
|
|
let repo_manager = RepoGroupManager::new("./data/repos", "./data/pkgs", "x86_64");
|
2023-07-13 14:58:27 +02:00
|
|
|
|
|
|
|
let global = Global {
|
|
|
|
config,
|
|
|
|
repo_manager: Arc::new(RwLock::new(repo_manager)),
|
|
|
|
};
|
2023-07-11 13:41:56 +02:00
|
|
|
|
|
|
|
// build our application with a single route
|
|
|
|
let app = Router::new()
|
2023-07-13 14:58:27 +02:00
|
|
|
.merge(repo::router(&global))
|
|
|
|
.with_state(global);
|
2023-07-11 13:41:56 +02:00
|
|
|
|
|
|
|
// run it with hyper on localhost:3000
|
|
|
|
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
|
|
|
|
.serve(app.into_make_service())
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
}
|