-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.rs
More file actions
40 lines (34 loc) · 987 Bytes
/
config.rs
File metadata and controls
40 lines (34 loc) · 987 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
40
use std::env;
pub struct Config {
pub host: String,
pub port: u16,
pub sentry_dsn: Option<String>,
}
impl Config {
pub fn new() -> Self {
let default = Config::default();
// Parse the host from the environment, defaulting to localhost
let host = env::var("HOST").unwrap_or(default.host);
// Parse the port from the environment, defaulting to 8080
let port = env::var("PORT")
.unwrap_or_else(|_| default.port.to_string())
.parse::<u16>()
.expect("PORT must be a valid u16 integer");
// Parse the sentry dsn from the environment, defaulting to None
let sentry_dsn = env::var("SENTRY_DSN").ok();
Config {
host,
port,
sentry_dsn,
}
}
}
impl Default for Config {
fn default() -> Self {
Config {
host: "127.0.0.1".to_string(),
port: 8080,
sentry_dsn: None,
}
}
}