Rewrite to rust

Co-authored-by: Kurbanov Bulat <kurbanovbul@gmail.com>
This commit is contained in:
Шатунов Антон
2024-05-06 23:04:24 +03:00
parent c52950e937
commit 26de50da3a
28 changed files with 3044 additions and 1681 deletions

35
src/config.rs Normal file
View File

@@ -0,0 +1,35 @@
use once_cell::sync::Lazy;
fn get_env(env: &'static str) -> String {
std::env::var(env).unwrap_or_else(|_| panic!("Cannot get the {} env variable", env))
}
pub struct Config {
pub api_key: String,
pub telegram_api_url: String,
pub telegram_chat_id: i64,
pub telegram_temp_chat_id: i64,
pub bot_tokens: Vec<String>,
pub sentry_dsn: String,
}
impl Config {
pub fn load() -> Config {
Config {
api_key: get_env("API_KEY"),
telegram_api_url: get_env("API_URL"),
telegram_chat_id: get_env("TELEGRAM_CHAT_ID").parse().unwrap(),
telegram_temp_chat_id: get_env("TELEGRAM_TEMP_CHAT_ID").parse().unwrap(),
bot_tokens: serde_json::from_str(&get_env("BOT_TOKENS")).unwrap(),
sentry_dsn: get_env("SENTRY_DSN"),
}
}
}
pub static CONFIG: Lazy<Config> = Lazy::new(Config::load);