aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs31
-rw-r--r--src/main.rs2
2 files changed, 24 insertions, 9 deletions
diff --git a/src/config.rs b/src/config.rs
index 18c3bab..2e9c1eb 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -4,30 +4,45 @@ use serde::Deserialize;
4use crate::auth; 4use crate::auth;
5 5
6#[derive(Debug, Clone, Deserialize)] 6#[derive(Debug, Clone, Deserialize)]
7#[serde(default)]
7pub struct Config { 8pub struct Config {
8 pub serveraddr: String, 9 pub addr: String,
9 pub pingtimeout: i64, 10 pub pingtimeout: i64,
10 pub pingthreshold: u64, 11 pub pingthreshold: u64,
11 pub auth: Auth, 12 pub auth: Auth,
12} 13}
13 14
15impl Default for Config {
16 fn default() -> Self {
17 Self {
18 addr: "0.0.0.0:7229".to_string(),
19 pingtimeout: 10,
20 pingthreshold: 1,
21 auth: Default::default(),
22 }
23 }
24}
25
14#[derive(Debug, Clone, Deserialize)] 26#[derive(Debug, Clone, Deserialize)]
15pub struct Auth { 27pub struct Auth {
16 pub method: auth::Methods, 28 pub method: auth::Methods,
17 pub secret: String, 29 pub secret: String,
18} 30}
19 31
32impl Default for Auth {
33 fn default() -> Self {
34 Self {
35 method: auth::Methods::None,
36 secret: String::new(),
37 }
38 }
39}
40
20impl Config { 41impl Config {
21 pub fn load() -> Result<Self, config::ConfigError> { 42 pub fn load() -> Result<Self, config::ConfigError> {
22 let config = config::Config::builder() 43 let config = config::Config::builder()
23 .set_default("serveraddr", "0.0.0.0:7229")? 44 .add_source(File::with_name("/etc/webol").required(false))
24 .set_default("pingtimeout", 10)?
25 .set_default("pingthreshold", 1)?
26 .set_default("timeoffset", 0)?
27 .set_default("auth.method", "none")?
28 .set_default("auth.secret", "")?
29 .add_source(File::with_name("config.toml").required(false)) 45 .add_source(File::with_name("config.toml").required(false))
30 .add_source(File::with_name("config.dev.toml").required(false))
31 .add_source(config::Environment::with_prefix("WEBOL").separator("_")) 46 .add_source(config::Environment::with_prefix("WEBOL").separator("_"))
32 .build()?; 47 .build()?;
33 48
diff --git a/src/main.rs b/src/main.rs
index edee184..7878669 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -120,7 +120,7 @@ async fn main() -> color_eyre::eyre::Result<()> {
120 .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi())) 120 .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
121 .with_state(Arc::new(shared_state)); 121 .with_state(Arc::new(shared_state));
122 122
123 let addr = config.serveraddr; 123 let addr = config.addr;
124 info!("start server on {}", addr); 124 info!("start server on {}", addr);
125 let listener = tokio::net::TcpListener::bind(addr).await?; 125 let listener = tokio::net::TcpListener::bind(addr).await?;
126 axum::serve(listener, app).await?; 126 axum::serve(listener, app).await?;