Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Nov 9, 2023
1 parent bed71b7 commit a65cea4
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 19 deletions.
7 changes: 5 additions & 2 deletions catalyst-gateway/bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;

use clap::Parser;

use crate::{logger, service, settings::Settings, state::State};
use crate::{logger, service, service_settings::ServiceSettings, state::State};

#[derive(thiserror::Error, Debug)]
/// All service errors
Expand All @@ -21,7 +21,9 @@ pub(crate) enum Error {
/// Simple service CLI options
pub(crate) enum Cli {
/// Run the service
Run(Settings),
Run(ServiceSettings),
/// Build API docs of the service
Docs,
}

impl Cli {
Expand All @@ -46,6 +48,7 @@ impl Cli {
service::run(&settings.address, state).await?;
Ok(())
},
Self::Docs => Ok(()),
}
}
}
17 changes: 8 additions & 9 deletions catalyst-gateway/bin/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ impl From<LogLevel> for tracing::Level {
}
}

impl LogLevel {
/// Map [`LogLevel`] to [`tracing::Level`]
pub(crate) fn as_log_level(self) -> tracing::log::LevelFilter {
match self {
LogLevel::Info => tracing::log::LevelFilter::Info,
LogLevel::Debug => tracing::log::LevelFilter::Debug,
LogLevel::Warn => tracing::log::LevelFilter::Warn,
LogLevel::Error => tracing::log::LevelFilter::Error,
impl From<LogLevel> for tracing::log::LevelFilter {
fn from(val: LogLevel) -> Self {
match val {
LogLevel::Debug => Self::Debug,
LogLevel::Info => Self::Info,
LogLevel::Warn => Self::Warn,
LogLevel::Error => Self::Error,
}
}
}
Expand All @@ -63,7 +62,7 @@ pub(crate) fn init(log_level: LogLevel) -> Result<(), SetGlobalDefaultError> {
.finish();

// Logging is globally disabled by default, so globally enable it to the required level.
tracing::log::set_max_level(log_level.as_log_level());
tracing::log::set_max_level(log_level.into());

tracing::subscriber::set_global_default(subscriber)
}
2 changes: 1 addition & 1 deletion catalyst-gateway/bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod event_db;
mod legacy_service;
mod logger;
mod service;
mod settings;
mod service_settings;
mod state;

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion catalyst-gateway/bin/src/service/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use test_endpoints::TestApi;
use v0::V0Api;
use v1::V1Api;

use crate::settings::API_URL_PREFIX;
use crate::service_settings::API_URL_PREFIX;

mod health;
mod registration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use uuid::Uuid;

/// While using macro-vis lib, you will get the `uncommon_codepoints` warning, so you will
/// probably want to place this in your crate root
use crate::settings::generate_github_issue_url;
use crate::service_settings::generate_github_issue_url;

/// Create a new Server Error Response.
/// Logging error message.
Expand Down
2 changes: 1 addition & 1 deletion catalyst-gateway/bin/src/service/poem_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
},
Error,
},
settings::{get_api_host_names, API_URL_PREFIX},
service_settings::{get_api_host_names, API_URL_PREFIX},
state::State,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tracing::{error, field, Instrument, Level, Span};
use ulid::Ulid;
use uuid::Uuid;

use crate::settings::CLIENT_ID_KEY;
use crate::service_settings::CLIENT_ID_KEY;

/// Labels for the metrics
const METRIC_LABELS: [&str; 3] = ["endpoint", "method", "status_code"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const API_URL_PREFIX_DEFAULT: &str = "/api";
/// the URL to the `PostgreSQL` event database,
/// and the logging level.
#[derive(Args, Clone)]
pub(crate) struct Settings {
pub(crate) struct ServiceSettings {
/// Server binding address
#[clap(long, default_value = ADDRESS_DEFAULT)]
pub(crate) address: SocketAddr,
Expand Down Expand Up @@ -256,10 +256,10 @@ mod tests {
// }

#[test]
fn generate_github_issue_url() {
fn generate_github_issue_url_test() {
let title = "Hello, World! How are you?";
assert_eq!(
super::generate_github_issue_url(title).unwrap().as_str(),
generate_github_issue_url(title).unwrap().as_str(),
"https://github.com/input-output-hk/catalyst-core/issues/new?template=bug_report.md&title=Hello%2C+World%21+How+are+you%3F"
);
}
Expand Down

0 comments on commit a65cea4

Please sign in to comment.