cat_gateway/service/
mod.rs

1//! Main entrypoint to the service
2
3// These Modules contain endpoints
4mod api;
5
6mod docs;
7// These modules are utility or common types/functions
8pub(crate) mod common;
9mod poem_service;
10pub(crate) mod utilities;
11
12use api::mk_api;
13pub(crate) use api::started;
14pub(crate) use poem_service::get_app_docs;
15use serde_json::{json, Value};
16use tracing::error;
17
18/// # Run Catalyst Gateway Service.
19///
20/// Runs the Poem based API.
21///
22/// ## Arguments
23///
24/// `settings`: &`DocsSetting` - settings for docs
25/// `state`: `Arc<State>` - the state
26///
27/// ## Errors
28///
29/// `Error::CannotRunService` - cannot run the service
30/// `Error::EventDbError` - cannot connect to the event db
31/// `Error::IoError` - An IO error has occurred.
32pub(crate) async fn run() -> anyhow::Result<()> {
33    poem_service::run().await
34}
35
36/// Retrieve the API specification in JSON format.
37pub(crate) fn api_spec() -> Value {
38    serde_json::from_str(&mk_api().spec()).unwrap_or_else(|err| {
39        error!(id="api_spec", error=?err, "Failed to parse API spec");
40        json!({})
41    })
42}