38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use crate::AppConfig;
|
|
|
|
impl AppConfig {
|
|
pub fn app_name(&self) -> anyhow::Result<String> {
|
|
if let Some(name) = self.env.get("APP_NAME") {
|
|
return Ok(name.to_string());
|
|
}
|
|
Ok(env!("CARGO_PKG_NAME").to_string())
|
|
}
|
|
|
|
pub fn app_version(&self) -> anyhow::Result<String> {
|
|
if let Some(version) = self.env.get("APP_VERSION") {
|
|
return Ok(version.to_string());
|
|
}
|
|
Ok(env!("CARGO_PKG_VERSION").to_string())
|
|
}
|
|
pub fn app_description(&self) -> anyhow::Result<String> {
|
|
if let Some(description) = self.env.get("APP_DESCRIPTION") {
|
|
return Ok(description.to_string());
|
|
}
|
|
Ok(env!("CARGO_PKG_DESCRIPTION").to_string())
|
|
}
|
|
|
|
pub fn api_port(&self) -> anyhow::Result<u16> {
|
|
if let Some(port) = self.env.get("APP_API_PORT") {
|
|
return Ok(port.parse::<u16>()?);
|
|
}
|
|
Ok(8080)
|
|
}
|
|
|
|
pub fn session_secret(&self) -> anyhow::Result<String> {
|
|
if let Some(secret) = self.env.get("APP_SESSION_SECRET") {
|
|
return Ok(secret.to_string());
|
|
}
|
|
Err(anyhow::anyhow!("APP_SESSION_SECRET not found"))
|
|
}
|
|
}
|