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
41
42
43
44
45
46
47
48
use std::process::exit;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Config {
pub auth_services: AuthConfigs,
pub address: String,
pub show_version: bool,
}
#[derive(Serialize, Deserialize)]
pub struct AuthConfig {
pub enabled: bool,
pub client_id: String,
pub client_secret: String,
}
#[derive(Serialize, Deserialize)]
pub struct AuthConfigs {
pub github: Option<AuthConfig>,
}
pub fn load_config(path: &str) -> Config {
if let Ok(read) = std::fs::read_to_string(path) {
if let Ok(config) = serde_json::from_str::<Config>(&read) {
return config;
} else {
println!("config.json does not contain a valid configuration.");
exit(1);
}
} else {
println!("Failed to load config.json.");
exit(1);
}
}