use std::sync::LazyLock; use tokio::sync::Mutex; use tokenservice_client::{ TokenService, TokenServiceApi }; pub struct TSClient(TokenService); impl Default for TSClient { fn default() -> Self { Self::new() } } impl TSClient { pub fn new() -> Self { let args: Vec = std::env::args().collect(); let service = if args.len() > 1 { &args[1] } else { "pgbot" }; Self(TokenService::new(service)) } pub async fn get(&self) -> Result> { match self.0.connect().await { Ok(api) => Ok(api), Err(e) => Err(e) } } } static TSCLIENT: LazyLock> = LazyLock::new(|| Mutex::new(TSClient::new())); pub async fn token_path() -> TokenServiceApi { TSCLIENT.lock().await.get().await.unwrap() }