From 55cfb8187cb814e17a2a99d02bfd9296fc01dcc2 Mon Sep 17 00:00:00 2001 From: mrw1593 Date: Fri, 30 Jun 2023 19:27:33 -0400 Subject: Added config file --- src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index da740be..e946161 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers, Logger, Normali use actix_web::web::Data; use actix_web::{dev, App, HttpServer}; +use bpaf::Bpaf; use exun::*; mod api; @@ -44,12 +45,28 @@ async fn delete_expired_tokens(db: MySqlPool) { } } +#[derive(Debug, Clone, Bpaf)] +#[bpaf(options, version)] +struct Opts { + /// The environment that the server is running in. Must be one of: local, + /// dev, staging, prod. + #[bpaf( + env("LOCKDAGGER_ENVIRONMENT"), + fallback(config::Environment::Local), + display_fallback + )] + env: config::Environment, +} + #[actix_web::main] async fn main() -> Result<(), RawUnexpected> { // load the environment file, but only in debug mode #[cfg(debug_assertions)] dotenv::dotenv()?; + let args = opts().run(); + config::set_environment(args.env); + // initialize the database let db_url = secrets::database_url()?; let sql_pool = db::initialize(&db_url).await?; -- cgit v1.2.3