Skip to content

Commit

Permalink
refactor: implement Default for Configuration sections
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed May 9, 2024
1 parent caae725 commit 69d7939
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
8 changes: 8 additions & 0 deletions packages/configuration/src/v1/health_check_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ pub struct HealthCheckApi {
/// system to choose a random port, use port `0`.
pub bind_address: String,
}

impl Default for HealthCheckApi {
fn default() -> Self {
Self {
bind_address: String::from("127.0.0.1:1313"),
}
}
}
12 changes: 12 additions & 0 deletions packages/configuration/src/v1/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ pub struct HttpTracker {
#[serde_as(as = "NoneAsEmptyString")]
pub ssl_key_path: Option<String>,
}

impl Default for HttpTracker {
fn default() -> Self {
Self {
enabled: false,
bind_address: String::from("0.0.0.0:7070"),
ssl_enabled: false,
ssl_cert_path: None,
ssl_key_path: None,
}
}
}
17 changes: 3 additions & 14 deletions packages/configuration/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,21 +346,10 @@ impl Default for Configuration {
udp_trackers: Vec::new(),
http_trackers: Vec::new(),
http_api: HttpApi::default(),
health_check_api: HealthCheckApi {
bind_address: String::from("127.0.0.1:1313"),
},
health_check_api: HealthCheckApi::default(),
};
configuration.udp_trackers.push(UdpTracker {
enabled: false,
bind_address: String::from("0.0.0.0:6969"),
});
configuration.http_trackers.push(HttpTracker {
enabled: false,
bind_address: String::from("0.0.0.0:7070"),
ssl_enabled: false,
ssl_cert_path: None,
ssl_key_path: None,
});
configuration.udp_trackers.push(UdpTracker::default());
configuration.http_trackers.push(HttpTracker::default());
configuration
}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/configuration/src/v1/udp_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ pub struct UdpTracker {
/// system to choose a random port, use port `0`.
pub bind_address: String,
}
impl Default for UdpTracker {
fn default() -> Self {
Self {
enabled: false,
bind_address: String::from("0.0.0.0:6969"),
}
}
}

0 comments on commit 69d7939

Please sign in to comment.