dns_wrapper/
api.rs

1use std::sync::RwLock;
2
3pub mod output;
4pub mod nation_resources;
5
6/// This is a global struct that stores the api key.
7/// Usage:
8/// ```ignore
9/// use dns-wrapper::api::ApiKey;
10/// ApiKey.set_apikey("APIKEY");
11/// ```
12///
13/// Should not be needed, but you can retrieve your api key with:
14/// ```ignore
15/// let api_key = ApiKey::get_apikey().ok_or("API key not set");
16/// ```
17pub struct ApiKey;
18
19static API_KEY: RwLock<Option<String>> = RwLock::new(None);
20
21impl ApiKey {
22    // Function to set an API Key
23    pub fn set_apikey(key: &str) {
24        let mut api_key = API_KEY.write().unwrap();
25        *api_key = Some(key.to_string())
26    }
27
28    // Retrieves a clone of the API Key
29    pub fn get_apikey() -> Option<String> {
30        let api_key = API_KEY.read().unwrap();
31        api_key.clone()
32    }
33}