-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathserver.rs
More file actions
39 lines (32 loc) 路 805 Bytes
/
Copy pathserver.rs
File metadata and controls
39 lines (32 loc) 路 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::net::{AddrParseError, SocketAddr};
use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)]
pub struct ServerConfig {
pub addr: String,
pub port: u16,
pub grace_shutdown_secs: i64,
}
impl ServerConfig {
pub fn get_addr(&self) -> String {
format!("{}:{}", self.addr, self.port)
}
pub fn get_http_addr(&self) -> String {
format!("http://{}:{}", self.addr, self.port)
}
pub fn get_socket_addr(&self) -> Result<SocketAddr, AddrParseError> {
self.get_addr().parse()
}
}
#[cfg(test)]
pub mod tests {
use super::*;
#[test]
pub fn app_config_http_addr_test() {
let config = ServerConfig {
addr: "127.0.0.1".to_string(),
port: 1024,
grace_shutdown_secs: 10,
};
assert_eq!(config.get_http_addr(), "http://127.0.0.1:1024");
}
}