refactor: Remove unnecessary clone() calls and improve error handling in packet-gateway

- Remove clone() from rating plan parameter in add_rating_plan call
- Remove clone() calls from ChargingEngineClient and EbpfManager initialization
- Remove clone() from Redis client Arc wrapping
- Remove clone() calls from PacketGatewayConfig field assignments
- Replace expect() with proper error handling using map_err and anyhow in health check server
- Remove clone() from IP string in session data collection
This commit is contained in:
nutcas3
2026-04-29 04:21:52 +03:00
parent b3ff568bd4
commit 4cc0b80b1c
2 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ pub async fn add_rating_plan(
sms_limit: req.get("sms_limit").and_then(|v| v.as_u64()).unwrap_or(100),
};
state.charging_engine.add_rating_plan(plan.clone()).await
state.charging_engine.add_rating_plan(plan).await
.with_context("Failed to add rating plan")?;
Ok(Json(serde_json::json!({
+9 -9
View File
@@ -88,13 +88,13 @@ async fn main() -> Result<()> {
info!("Connected to Redis successfully");
// Initialize charging engine client
let charging_client = ChargingEngineClient::new(args.charging_engine_url.clone());
let charging_client = ChargingEngineClient::new(&args.charging_engine_url);
info!("Charging engine client initialized");
#[cfg(feature = "ebpf")]
let (ebpf_manager, ebpf_attached) = {
// Initialize eBPF manager
let mut ebpf_manager = EbpfManager::new(args.interface.clone()).await
let mut ebpf_manager = EbpfManager::new(&args.interface).await
.context("Failed to initialize eBPF manager")?;
// Load and attach XDP program
@@ -123,7 +123,7 @@ async fn main() -> Result<()> {
info!("Packet gateway running. Press Ctrl+C to exit.");
// Start HTTP health check server
let redis_client_arc = Arc::new(redis_client.clone());
let redis_client_arc = Arc::new(redis_client);
let ebpf_attached_clone = Arc::clone(&ebpf_attached);
#[cfg(feature = "ebpf")]
@@ -133,9 +133,9 @@ async fn main() -> Result<()> {
// Create config state
let config = PacketGatewayConfig {
interface: args.interface.clone(),
redis_url: args.redis_url.clone(),
charging_engine_url: args.charging_engine_url.clone(),
interface: args.interface,
redis_url: args.redis_url,
charging_engine_url: args.charging_engine_url,
sync_interval: args.sync_interval,
health_port: args.health_port,
};
@@ -167,9 +167,9 @@ async fn main() -> Result<()> {
info!("Health check server listening on {}", addr);
let listener = tokio::net::TcpListener::bind(&addr).await
.expect("Failed to bind health check server");
.map_err(|e| anyhow::anyhow!("Failed to bind health check server: {}", e))?;
axum::serve(listener, app).await
.expect("Failed to start health check server");
.map_err(|e| anyhow::anyhow!("Failed to start health check server: {}", e))?;
});
// Main synchronization loop with graceful shutdown
@@ -215,7 +215,7 @@ async fn main() -> Result<()> {
s.ip & 0xFF
);
let session_id = format!("session-{}", ip_str);
(ip_str.clone(), session_id, s.bytes)
(ip_str, session_id, s.bytes)
})
.collect();