Skip to main content

gooty_proxy/config/
schema.rs

1//! # Configuration Schema
2//!
3//! This module defines the structure of the application's configuration.
4//! It includes settings for various components such as HTTP client, proxy management, and storage.
5//!
6//! ## Overview
7//!
8//! The schema is responsible for:
9//! - Defining configuration structures
10//! - Providing default values for configuration fields
11//! - Serializing and deserializing configuration to/from TOML
12//!
13//! ## Examples
14//!
15//! ```
16//! use gooty_proxy::config::schema::AppConfig;
17//!
18//! let config = AppConfig::default();
19//! println!("Default log level: {}", config.application.log_level);
20//! ```
21
22use serde::{Deserialize, Serialize};
23
24/// Main application configuration
25#[derive(Debug, Clone, Serialize, Deserialize, Default)]
26pub struct AppConfig {
27    /// Application-wide settings
28    #[serde(default)]
29    pub application: ApplicationConfig,
30
31    /// HTTP client settings
32    #[serde(default)]
33    pub http: HttpConfig,
34
35    /// Proxy judge settings
36    #[serde(default)]
37    pub judge: JudgeConfig,
38
39    /// Proxy management settings
40    #[serde(default)]
41    pub proxies: ProxiesConfig,
42
43    /// Storage and persistence settings
44    #[serde(default)]
45    pub storage: StorageConfig,
46}
47
48/// Application-wide configuration settings
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct ApplicationConfig {
51    /// Logging level (error, warn, info, debug, trace)
52    pub log_level: String,
53}
54
55impl Default for ApplicationConfig {
56    fn default() -> Self {
57        Self {
58            log_level: "info".to_string(),
59        }
60    }
61}
62
63/// HTTP client configuration
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct HttpConfig {
66    /// Request timeout in seconds
67    pub request_timeout_secs: u64,
68
69    /// Number of retry attempts for failed requests
70    pub request_retries: u32,
71
72    /// Delay between sequential requests in milliseconds
73    pub request_delay_ms: u64,
74}
75
76impl Default for HttpConfig {
77    fn default() -> Self {
78        Self {
79            request_timeout_secs: 30,
80            request_retries: 3,
81            request_delay_ms: 500,
82        }
83    }
84}
85
86/// Configuration for proxy judge services
87#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct JudgeConfig {
89    /// Number of proxies to validate in parallel
90    pub parallel_validations: usize,
91
92    /// Maximum acceptable latency for proxies in milliseconds
93    pub max_acceptable_latency_ms: u32,
94}
95
96impl Default for JudgeConfig {
97    fn default() -> Self {
98        Self {
99            parallel_validations: 20,
100            max_acceptable_latency_ms: 2000,
101        }
102    }
103}
104
105/// Proxy management configuration
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct ProxiesConfig {
108    /// Minimum success rate threshold for proxies
109    pub min_success_rate: f64,
110}
111
112impl Default for ProxiesConfig {
113    fn default() -> Self {
114        Self {
115            min_success_rate: 0.7,
116        }
117    }
118}
119
120/// Storage and persistence configuration
121#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct StorageConfig {
123    /// Directory where data is stored
124    pub data_dir: String,
125
126    /// Whether to create default files when they don't exist
127    pub create_defaults_if_missing: bool,
128
129    /// How often to auto-save data (in seconds)
130    pub auto_save_interval_secs: u64,
131
132    /// Whether to pretty-print TOML output
133    pub pretty_print: bool,
134}
135
136impl Default for StorageConfig {
137    fn default() -> Self {
138        Self {
139            data_dir: "data".to_string(),
140            create_defaults_if_missing: true,
141            auto_save_interval_secs: 300,
142            pretty_print: true,
143        }
144    }
145}