mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
refactor: use lowercase names for run environment and config files (#801)
This commit is contained in:
@ -3,7 +3,6 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
/// Environment variables accessed by the application. This module aims to be the source of truth
|
||||
/// containing all environment variable that the application accesses.
|
||||
@ -11,7 +10,7 @@ pub mod vars {
|
||||
/// Parent directory where `Cargo.toml` is stored.
|
||||
pub const CARGO_MANIFEST_DIR: &str = "CARGO_MANIFEST_DIR";
|
||||
|
||||
/// Environment variable that sets Development/Sandbox/Production environment.
|
||||
/// Environment variable that sets development/sandbox/production environment.
|
||||
pub const RUN_ENV: &str = "RUN_ENV";
|
||||
|
||||
/// Directory of config TOML files. Default is `config`.
|
||||
@ -19,7 +18,11 @@ pub mod vars {
|
||||
}
|
||||
|
||||
/// Current environment.
|
||||
#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, Display, EnumString)]
|
||||
#[derive(
|
||||
Debug, Default, Deserialize, Serialize, Clone, Copy, strum::Display, strum::EnumString,
|
||||
)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
pub enum Env {
|
||||
/// Development environment.
|
||||
#[default]
|
||||
@ -30,7 +33,7 @@ pub enum Env {
|
||||
Production,
|
||||
}
|
||||
|
||||
/// Name of current environment. Either "Development", "Sandbox" or "Production".
|
||||
/// Name of current environment. Either "development", "sandbox" or "production".
|
||||
pub fn which() -> Env {
|
||||
#[cfg(debug_assertions)]
|
||||
let default_env = Env::Development;
|
||||
|
||||
@ -123,8 +123,8 @@ impl Config {
|
||||
// 1. Defaults from the implementation of the `Default` trait.
|
||||
// 2. Values from config file. The config file accessed depends on the environment
|
||||
// specified by the `RUN_ENV` environment variable. `RUN_ENV` can be one of
|
||||
// `Development`, `Sandbox` or `Production`. If nothing is specified for `RUN_ENV`,
|
||||
// `/config/Development.toml` file is read.
|
||||
// `development`, `sandbox` or `production`. If nothing is specified for `RUN_ENV`,
|
||||
// `/config/development.toml` file is read.
|
||||
// 3. Environment variables prefixed with `ROUTER` and each level separated by double
|
||||
// underscores.
|
||||
//
|
||||
@ -166,9 +166,9 @@ impl Config {
|
||||
let config_directory =
|
||||
std::env::var(crate::env::vars::CONFIG_DIR).unwrap_or_else(|_| "config".into());
|
||||
let config_file_name = match environment {
|
||||
"Production" => "Production.toml",
|
||||
"Sandbox" => "Sandbox.toml",
|
||||
_ => "Development.toml",
|
||||
"production" => "production.toml",
|
||||
"sandbox" => "sandbox.toml",
|
||||
_ => "development.toml",
|
||||
};
|
||||
|
||||
config_path.push(crate::env::workspace_path());
|
||||
|
||||
Reference in New Issue
Block a user