Skip to content

Commit

Permalink
chore: Config update
Browse files Browse the repository at this point in the history
  • Loading branch information
czareko committed Sep 27, 2024
1 parent 95588e0 commit 1d83e0a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ prometheus = "0.13"
lazy_static = "1.4"
warp = "0.3.7"


[[bin]]
name = "ring_bench_rs"
path = "src/main.rs"
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ services:
# rust-app:
# build: .
# ports:
# - "${SERVER_PORT_HTTP:-8080}:8080"
# - "${PROMETHEUS_PORT_HTTP:-3030}:3030"
# environment:
# RUST_LOG: "info"
# SERVER_PORT_HTTP: ${SERVER_PORT_HTTP:-8080}
# PROMETHEUS_PORT_HTTP: ${PROMETHEUS_PORT_HTTP:-3030}
# TRADING_PAIR: ${TRADING_PAIR:-BTCFDUSD}
# volumes:
# - ./resources/config.toml:/usr/src/app/resources/config.toml
Expand Down
2 changes: 1 addition & 1 deletion resources/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[default]
server_port_http = 8080
prometheus_port_http = 3030
trading_pair = "BTCFDUSD"
ws_config_retry_count = 10
ws_config_retry_max = 20
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use once_cell::sync::Lazy;

#[derive(Debug, Deserialize)]
pub struct DefaultConfig {
pub server_port_http: u16,
pub prometheus_port_http: u16,
pub trading_pair: String,
pub ws_config_retry_max: u16,
}

enum EnvVar {
ServerPortHTTP,
PrometheusPortHTTP,
TradingPair,
WSConfigRetryMax
}
Expand All @@ -39,7 +39,7 @@ impl EnvVar {
// Returns the environment variable name as a &str
fn as_str(&self) -> &str {
match self {
EnvVar::ServerPortHTTP => "SERVER_PORT_HTTP",
EnvVar::PrometheusPortHTTP => "SERVER_PORT_HTTP",
EnvVar::TradingPair => "TRADING_PAIR",
EnvVar::WSConfigRetryMax => "WS_CONFIG_RETRY_MAX"
}
Expand Down Expand Up @@ -76,8 +76,8 @@ pub fn load_config_from_env_or_file() -> Result<AppConfig, Box<dyn Error>> {
let mut config = load_config()?;

// Override with environment variables if they exist
config.default.server_port_http = EnvVar::ServerPortHTTP
.get_value(&config.default.server_port_http); // u16 for server_port_http
config.default.prometheus_port_http = EnvVar::PrometheusPortHTTP
.get_value(&config.default.prometheus_port_http); // u16 for server_port_http

config.default.trading_pair = EnvVar::TradingPair
.get_value(&config.default.trading_pair); // String for trading_pair
Expand Down

0 comments on commit 1d83e0a

Please sign in to comment.