Skip to content

Commit 5d49485

Browse files
Merge pull request #41 from code0-tech/40-new-config-system
New Config System
2 parents a4e28c9 + d167432 commit 5d49485

6 files changed

Lines changed: 213 additions & 11 deletions

File tree

.env-example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ENVIRONMENT='development'
2+
MODE='dynamic'
3+
RABBITMQ_URL='amqp://localhost:5672'
4+
AQUILA_URL='http://localhost:8080'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ target
44
.DS_Store
55
./out
66
out
7+
8+
.env

Cargo.lock

Lines changed: 150 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[package]
22
name = "taurus"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
7-
code0-flow = { version = "0.0.12", features = ["all"] }
7+
code0-flow = { version = "0.0.13" }
88
tucana = { version = "0.0.28", features = ["aquila"] }
99
lapin = "2.5.3"
1010
serde = "1.0.219"
@@ -13,6 +13,7 @@ tokio = { version = "1.44.1", features = ["rt-multi-thread"] }
1313
toml = "0.8.0"
1414
log = "0.4.27"
1515
futures-lite = "2.6.0"
16+
env_logger = "0.11.8"
1617

1718
[dev-dependencies]
1819
tempfile = "3.19.1"

src/configuration.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use code0_flow::flow_config::{env_with_default, environment::Environment, mode::Mode};
2+
3+
/// Struct for all relevant `Taurus` startup configurations
4+
pub struct Config {
5+
/// Options:
6+
/// `development` (default)
7+
/// `staging`
8+
/// `production`
9+
pub environment: Environment,
10+
11+
/// Aquila mode
12+
///
13+
/// Options:
14+
/// `static` (default)
15+
/// `hybrid`
16+
pub mode: Mode,
17+
18+
/// Verification Token required for internal communication
19+
pub rabbitmq_url: String,
20+
21+
/// URL to the `Sagittarius` Server.
22+
pub aquila_url: String,
23+
}
24+
25+
/// Implementation for all relevant `Aquila` startup configurations
26+
///
27+
/// Behavior:
28+
/// Searches for the env. file at root level. Filename: `.env`
29+
impl Config {
30+
pub fn new() -> Self {
31+
Config {
32+
environment: env_with_default("ENVIRONMENT", Environment::Development),
33+
mode: env_with_default("MODE", Mode::STATIC),
34+
rabbitmq_url: env_with_default("RABBITMQ_URL", String::from("amqp://localhost:5672")),
35+
aquila_url: env_with_default("AQUILA_URL", String::from("http://localhost:8080")),
36+
}
37+
}
38+
}

src/main.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
mod configuration;
12
pub mod context;
23
pub mod error;
34
pub mod implementation;
45
pub mod locale;
56
pub mod registry;
6-
77
use std::sync::Arc;
88

9-
use code0_flow::flow_queue::service::{Message, RabbitmqClient};
9+
use code0_flow::{
10+
flow_config::load_env_file,
11+
flow_queue::service::{Message, RabbitmqClient},
12+
};
1013
use context::{Context, ContextEntry, ContextResult};
1114
use error::RuntimeError;
1215
use futures_lite::StreamExt;
@@ -15,6 +18,8 @@ use locale::locale::Locale;
1518
use registry::FunctionStore;
1619
use tucana::shared::{Flow, NodeFunction, Value};
1720

21+
use crate::configuration::Config;
22+
1823
fn handle_node_function(
1924
function: NodeFunction,
2025
store: &FunctionStore,
@@ -165,10 +170,18 @@ fn handle_message(message: Message, store: &FunctionStore) -> Result<Message, la
165170

166171
#[tokio::main]
167172
async fn main() {
173+
env_logger::Builder::from_default_env()
174+
.filter_level(log::LevelFilter::Debug)
175+
.init();
176+
177+
load_env_file();
178+
179+
let config = Config::new();
180+
168181
let _locale = Locale::default();
169182
let store = FunctionStore::new();
170183

171-
let rabbitmq_client = Arc::new(RabbitmqClient::new("amqp://localhost:5672").await);
184+
let rabbitmq_client = Arc::new(RabbitmqClient::new(config.rabbitmq_url.as_str()).await);
172185

173186
let mut consumer = {
174187
let channel = rabbitmq_client.channel.lock().await;

0 commit comments

Comments
 (0)