Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-duplicate database_url between ENV and config.ymls #196

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ pub struct Cli {
#[serde(tag = "type", rename_all = "snake_case")]
#[serde(deny_unknown_fields)]
pub enum DbConfig {
Postgres { database_url: String },
Postgres {
#[serde(default = "get_env_db_url")]
database_url: String,
},
}

#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
#[serde(deny_unknown_fields)]
pub enum SinkConfig {
Cardano { db: DbConfig, network: String },
Cardano {
db: DbConfig,
#[serde(default = "get_env_network")]
network: String,
},
}

pub enum Network {}
Expand All @@ -76,6 +83,15 @@ pub struct Config {
start_block: Option<String>,
}

fn get_env_db_url() -> String {
std::env::var("DATABASE_URL")
.expect("env DATABASE_URL not found and config did not specify sink.db.database_url")
}

fn get_env_network() -> String {
std::env::var("NETWORK").expect("env NETWORK not found and config did not specify sink.network")
}

#[allow(unreachable_patterns)]
#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down
Loading