1use std::time::Duration;
2use std::error::Error;
3
4pub struct Cachier {
5 url: String,
6 storage: String,
7}
8
9impl Cachier {
10 pub fn new(url: String, storage: String) -> Self {
11 return Cachier {url: url, storage: storage};
12 }
13
14 pub async fn get(&self, key: Option<&str>) {
15 match key {
16 Some(key) => {
17 let result = self.__get(key).await;
18 match result {
19 Ok(result) => println!("{:?}", result),
20 Err(result) => println!("{:?}", result),
21 }
22 },
23 None => println!("none"),
24 }
25 }
26
27 async fn __get(&self, key: &str) -> Result<(), Box<dyn Error>> {
28 let client = reqwest::Client::new();
29 let doge = client
30 .get(format!("{url}?cache_key={key}&driver={driver}", url=self.url, key=key, driver=self.storage))
31 .header("Accept", "text/plain")
32 .timeout(Duration::from_secs(3))
33 .send()
34 .await?
35 .text()
36 .await?;
37 println!("{:}", doge);
38 Ok(())
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn it_works() {
48 }
49}