Skip to content

Commit 9d6b7a0

Browse files
committed
feat: implemented new config system
1 parent a4e28c9 commit 9d6b7a0

4 files changed

Lines changed: 60 additions & 3 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

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)