From 47e7606370fc5e292c14032ad5f4fb9c86426eb7 Mon Sep 17 00:00:00 2001 From: irenjj Date: Thu, 11 Apr 2024 22:08:12 +0800 Subject: [PATCH] fix: replace if else with match --- src/servers/src/http.rs | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/servers/src/http.rs b/src/servers/src/http.rs index 087f61b664e0..e99f56324074 100644 --- a/src/servers/src/http.rs +++ b/src/servers/src/http.rs @@ -705,23 +705,28 @@ impl HttpServer { strict_mode: bool, ) -> Router { let mut router = Router::new().route("/read", routing::post(prom_store::remote_read)); - if prom_store_with_metric_engine && strict_mode { - router = router.route("/write", routing::post(prom_store::remote_write)); - } else if prom_store_with_metric_engine && !strict_mode { - router = router.route( - "/write", - routing::post(prom_store::remote_write_without_strict_mode), - ); - } else if !prom_store_with_metric_engine && strict_mode { - router = router.route( - "/write", - routing::post(prom_store::route_write_without_metric_engine), - ); - } else { - router = router.route( - "/write", - routing::post(prom_store::route_write_without_metric_engine_and_strict_mode), - ); + match (prom_store_with_metric_engine, strict_mode) { + (true, true) => { + router = router.route("/write", routing::post(prom_store::remote_write)) + } + (true, false) => { + router = router.route( + "/write", + routing::post(prom_store::remote_write_without_strict_mode), + ) + } + (false, true) => { + router = router.route( + "/write", + routing::post(prom_store::route_write_without_metric_engine), + ) + } + (false, false) => { + router = router.route( + "/write", + routing::post(prom_store::route_write_without_metric_engine_and_strict_mode), + ) + } } router.with_state(prom_handler) }