Add rust implementation

This commit is contained in:
2022-12-14 22:33:38 +01:00
parent e36487b5ad
commit a5827721cd
39 changed files with 2473 additions and 1410 deletions

45
src/config.rs Normal file
View File

@@ -0,0 +1,45 @@
use serde::Deserialize;
fn get_env(env: &'static str) -> String {
std::env::var(env).unwrap_or_else(|_| panic!("Cannot get the {} env variable", env))
}
#[derive(Deserialize, Clone)]
pub struct SourceConfig {
pub url: String,
pub proxy: Option<String>
}
pub struct Config {
pub api_key: String,
pub fl_sources: Vec<SourceConfig>,
pub book_library_api_key: String,
pub book_library_url: String,
pub converter_url: String,
pub sentry_dsn: String
}
impl Config {
pub fn load() -> Config {
Config {
api_key: get_env("API_KEY"),
fl_sources: serde_json::from_str(&get_env("FL_SOURCES")).unwrap(),
book_library_api_key: get_env("BOOK_LIBRARY_API_KEY"),
book_library_url: get_env("BOOK_LIBRARY_URL"),
converter_url: get_env("CONVERTER_URL"),
sentry_dsn: get_env("SENTRY_DSN")
}
}
}
lazy_static! {
pub static ref CONFIG: Config = Config::load();
}