refactor: partially migrate to singleton pattern

This commit is contained in:
zhom
2025-07-31 22:29:08 +04:00
parent 4997854577
commit 5b31cfaf32
9 changed files with 131 additions and 1032 deletions
+10 -1
View File
@@ -315,7 +315,7 @@ pub struct ApiClient {
}
impl ApiClient {
pub fn new() -> Self {
fn new() -> Self {
Self {
client: Client::new(),
firefox_api_base: "https://product-details.mozilla.org/1.0".to_string(),
@@ -327,6 +327,10 @@ impl ApiClient {
}
}
pub fn instance() -> &'static ApiClient {
&API_CLIENT
}
#[cfg(test)]
pub fn new_with_base_urls(
firefox_api_base: String,
@@ -1336,6 +1340,11 @@ impl ApiClient {
}
}
// Global singleton instance
lazy_static::lazy_static! {
static ref API_CLIENT: ApiClient = ApiClient::new();
}
#[cfg(test)]
mod tests {
use super::*;