Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add core and api crates #11

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ readme = "README.md"
rust-version = "1.79"

[workspace.dependencies]
arch-api = { path = "crates/api" }
arch-core = { path = "crates/core"}

async-trait = "0.1.81"

[workspace.dependencies.tokio]
version = "1.39.1"
Expand Down
12 changes: 12 additions & 0 deletions crates/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "arch-api"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
readme.workspace = true
rust-version.workspace = true

[dependencies]
14 changes: 14 additions & 0 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
2 changes: 2 additions & 0 deletions crates/apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ anyhow = "1.0.86"
log = "0.4.22"
tracing-log = "0.2.0"

arch-core.workspace = true

tokio.workspace = true
tracing.workspace = true

Expand Down
4 changes: 4 additions & 0 deletions crates/apps/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use arch_core::create_service;

use anyhow::Result;

mod logging;
Expand All @@ -6,7 +8,9 @@ mod logging;
async fn main() -> Result<()> {
logging::init_logging()?;

let arch_service = create_service();
tracing::info!("Hello, world!");
tracing::info!("Healthy={}", arch_service.health_service.is_healthy().await);

Ok(())
}
13 changes: 13 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "arch-core"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
readme.workspace = true
rust-version.workspace = true

[dependencies]
async-trait.workspace = true
12 changes: 12 additions & 0 deletions crates/core/src/health.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use async_trait::async_trait;

use crate::HealthService;

Check failure on line 3 in crates/core/src/health.rs

View workflow job for this annotation

GitHub Actions / Check for spelling errors

crate ==> create

pub(crate) struct HealthServiceImpl {}

Check failure on line 5 in crates/core/src/health.rs

View workflow job for this annotation

GitHub Actions / Check for spelling errors

crate ==> create

#[async_trait]
impl HealthService for HealthServiceImpl {
async fn is_healthy(&self) -> bool {
true
}
}
19 changes: 19 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use async_trait::async_trait;
use health::HealthServiceImpl;

mod health;

#[async_trait]
pub trait HealthService {
async fn is_healthy(&self) -> bool;
}

pub struct ArchService {
pub health_service: Box<dyn HealthService>,
}

pub fn create_service() -> ArchService {
let health_service = Box::new(HealthServiceImpl {});

ArchService { health_service }
}