Skip to content

Commit 69d7939

Browse files
committed
refactor: implement Default for Configuration sections
1 parent caae725 commit 69d7939

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

packages/configuration/src/v1/health_check_api.rs

+8
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ pub struct HealthCheckApi {
1111
/// system to choose a random port, use port `0`.
1212
pub bind_address: String,
1313
}
14+
15+
impl Default for HealthCheckApi {
16+
fn default() -> Self {
17+
Self {
18+
bind_address: String::from("127.0.0.1:1313"),
19+
}
20+
}
21+
}

packages/configuration/src/v1/http_tracker.rs

+12
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ pub struct HttpTracker {
2121
#[serde_as(as = "NoneAsEmptyString")]
2222
pub ssl_key_path: Option<String>,
2323
}
24+
25+
impl Default for HttpTracker {
26+
fn default() -> Self {
27+
Self {
28+
enabled: false,
29+
bind_address: String::from("0.0.0.0:7070"),
30+
ssl_enabled: false,
31+
ssl_cert_path: None,
32+
ssl_key_path: None,
33+
}
34+
}
35+
}

packages/configuration/src/v1/mod.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,10 @@ impl Default for Configuration {
346346
udp_trackers: Vec::new(),
347347
http_trackers: Vec::new(),
348348
http_api: HttpApi::default(),
349-
health_check_api: HealthCheckApi {
350-
bind_address: String::from("127.0.0.1:1313"),
351-
},
349+
health_check_api: HealthCheckApi::default(),
352350
};
353-
configuration.udp_trackers.push(UdpTracker {
354-
enabled: false,
355-
bind_address: String::from("0.0.0.0:6969"),
356-
});
357-
configuration.http_trackers.push(HttpTracker {
358-
enabled: false,
359-
bind_address: String::from("0.0.0.0:7070"),
360-
ssl_enabled: false,
361-
ssl_cert_path: None,
362-
ssl_key_path: None,
363-
});
351+
configuration.udp_trackers.push(UdpTracker::default());
352+
configuration.http_trackers.push(HttpTracker::default());
364353
configuration
365354
}
366355
}

packages/configuration/src/v1/udp_tracker.rs

+8
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ pub struct UdpTracker {
1010
/// system to choose a random port, use port `0`.
1111
pub bind_address: String,
1212
}
13+
impl Default for UdpTracker {
14+
fn default() -> Self {
15+
Self {
16+
enabled: false,
17+
bind_address: String::from("0.0.0.0:6969"),
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)