perfgate_client/lib.rs
1//! # perfgate-client
2//!
3//! A Rust client library for the perfgate baseline service.
4//!
5//! This crate provides a client for interacting with the perfgate baseline
6//! service API, including:
7//!
8//! - Uploading and downloading baselines
9//! - Listing baselines with filtering
10//! - Promoting and deleting baselines
11//! - Health checking
12//! - Automatic fallback to local storage when the server is unavailable
13//!
14//! ## Quick Start
15//!
16//! ```rust,no_run
17//! use perfgate_client::{BaselineClient, ClientConfig, ListBaselinesQuery};
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//! // Create a client
22//! let config = ClientConfig::new("https://perfgate.example.com/api/v1")
23//! .with_api_key("your-api-key");
24//!
25//! let client = BaselineClient::new(config)?;
26//!
27//! // Check server health
28//! let health = client.health_check().await?;
29//! println!("Server status: {}", health.status);
30//!
31//! // List baselines
32//! let query = ListBaselinesQuery::new().with_limit(10);
33//! let response = client.list_baselines("my-project", &query).await?;
34//!
35//! for baseline in &response.baselines {
36//! println!("{}: {}", baseline.benchmark, baseline.version);
37//! }
38//!
39//! Ok(())
40//! }
41//! ```
42//!
43//! ## Fallback Storage
44//!
45//! When the server is unavailable, the client can fall back to local file storage:
46//!
47//! ```rust,no_run
48//! use perfgate_client::{BaselineClient, ClientConfig, FallbackClient, FallbackStorage};
49//!
50//! #[tokio::main]
51//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
52//! let config = ClientConfig::new("https://perfgate.example.com/api/v1")
53//! .with_api_key("your-api-key")
54//! .with_fallback(FallbackStorage::local("./baselines"));
55//!
56//! let client = BaselineClient::new(config)?;
57//! let fallback_client = FallbackClient::new(
58//! client,
59//! Some(FallbackStorage::local("./baselines")),
60//! );
61//!
62//! // This will fall back to local storage if the server is unavailable
63//! let baseline = fallback_client
64//! .get_latest_baseline("my-project", "my-bench")
65//! .await?;
66//!
67//! Ok(())
68//! }
69//! ```
70//!
71//! ## Error Handling
72//!
73//! The client provides detailed error types for different failure scenarios:
74//!
75//! ```rust,no_run
76//! use perfgate_client::{BaselineClient, ClientConfig, ClientError};
77//!
78//! #[tokio::main]
79//! async fn main() {
80//! let config = ClientConfig::new("https://perfgate.example.com/api/v1");
81//! let client = BaselineClient::new(config).unwrap();
82//!
83//! match client.get_latest_baseline("my-project", "my-bench").await {
84//! Ok(baseline) => println!("Got baseline: {}", baseline.id),
85//! Err(ClientError::NotFoundError(msg)) => {
86//! eprintln!("Baseline not found: {}", msg);
87//! }
88//! Err(ClientError::AuthError(msg)) => {
89//! eprintln!("Authentication failed: {}", msg);
90//! }
91//! Err(ClientError::ConnectionError(msg)) => {
92//! eprintln!("Server unavailable: {}", msg);
93//! }
94//! Err(e) => eprintln!("Error: {}", e),
95//! }
96//! }
97//! ```
98
99pub mod client;
100pub mod config;
101pub mod error;
102pub mod fallback;
103pub mod types;
104
105// Re-export main types at the crate root for convenience
106pub use client::BaselineClient;
107pub use config::{AuthMethod, ClientConfig, FallbackStorage, RetryConfig};
108pub use error::ClientError;
109pub use fallback::FallbackClient;
110pub use types::{
111 BaselineRecord, BaselineSource, BaselineSummary, DeleteBaselineResponse, HealthResponse,
112 ListBaselinesQuery, ListBaselinesResponse, ListVerdictsQuery, ListVerdictsResponse,
113 PaginationInfo, PromoteBaselineRequest, PromoteBaselineResponse, StorageHealth,
114 SubmitVerdictRequest, UploadBaselineRequest, UploadBaselineResponse, VerdictRecord,
115};
116
117#[cfg(test)]
118mod tests {
119 use super::*;
120
121 #[test]
122 fn test_reexports() {
123 // Ensure all re-exports are accessible
124 let _config = ClientConfig::new("https://example.com");
125 let _query = ListBaselinesQuery::new();
126 }
127}