Skip to content

Commit 99188b1

Browse files
committed
refactor: 优化BeatRequest处理逻辑,使用StringUtils简化空值检查并提前返回默认BeatInfo
1 parent 5a35b4f commit 99188b1

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/openapi/naming/model.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(unused_imports, unused_assignments, unused_variables)]
22
use crate::common::option_utils::OptionUtils;
3+
use crate::common::string_utils::StringUtils;
34
use crate::naming::model::{Instance, ServiceKey};
45
use crate::naming::service::{ServiceInfoDto, SubscriberInfoDto};
56
use crate::naming::NamingUtils;
@@ -250,7 +251,7 @@ impl BeatRequest {
250251

251252
pub fn convert_to_instance(self) -> anyhow::Result<Instance> {
252253
let mut beat_info = self.get_beat_info()?;
253-
let use_beat = self.beat.as_ref().is_some_and(|s| !s.is_empty());
254+
let use_beat = !StringUtils::is_option_empty(&self.beat);
254255
if !use_beat {
255256
beat_info.ip = self.ip;
256257
beat_info.port = self.port;
@@ -287,6 +288,9 @@ impl BeatRequest {
287288
}
288289

289290
fn get_beat_info(&self) -> anyhow::Result<BeatInfo> {
291+
if StringUtils::is_option_empty(&self.beat) {
292+
return Ok(BeatInfo::default());
293+
}
290294
let beat_str = self.beat.clone().unwrap_or_default();
291295
if let Some(beat_str) = self.beat.as_ref() {
292296
let v = serde_json::from_str::<BeatInfo>(beat_str)?;

0 commit comments

Comments
 (0)