photoncloud-monorepo/creditservice/creditservice-client/examples/builder.rs

27 lines
931 B
Rust

//! Minimal builder example for CreditService client
use creditservice_client::Client;
use photocloud_client_common::AuthConfig;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Point to your CreditService endpoint (plaintext for example only)
let mut client = Client::builder("http://127.0.0.1:50052")
.auth(AuthConfig::None)
.build()
.await?;
// Fetch or create a wallet
let project_id = "demo-project";
match client.get_wallet(project_id).await {
Ok(wallet) => println!("Wallet balance: {}", wallet.balance),
Err(status) if status.code() == tonic::Code::NotFound => {
let wallet = client
.create_wallet(project_id, "demo-org", 1_000)
.await?;
println!("Created wallet with balance: {}", wallet.balance);
}
Err(err) => return Err(Box::new(err)),
}
Ok(())
}