diff options
author | fxqnlr <[email protected]> | 2024-10-06 15:45:09 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-10-06 15:45:09 +0200 |
commit | 7740bf12633a3c7c2e461aa8b74c852efbb9318b (patch) | |
tree | 9d4f048540c123c0ca6426acdeb8f56c7083978c /src | |
parent | 843414433d68b7a7d1b60f814621766bcfca2206 (diff) | |
parent | ae386a491b23cfbadc4da8680c8ebcb85310dcb5 (diff) | |
download | webol-main.tar webol-main.tar.gz webol-main.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 31 | ||||
-rw-r--r-- | src/main.rs | 2 |
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; | |||
4 | use crate::auth; | 4 | use crate::auth; |
5 | 5 | ||
6 | #[derive(Debug, Clone, Deserialize)] | 6 | #[derive(Debug, Clone, Deserialize)] |
7 | #[serde(default)] | ||
7 | pub struct Config { | 8 | pub 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 | ||
15 | impl 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)] |
15 | pub struct Auth { | 27 | pub struct Auth { |
16 | pub method: auth::Methods, | 28 | pub method: auth::Methods, |
17 | pub secret: String, | 29 | pub secret: String, |
18 | } | 30 | } |
19 | 31 | ||
32 | impl Default for Auth { | ||
33 | fn default() -> Self { | ||
34 | Self { | ||
35 | method: auth::Methods::None, | ||
36 | secret: String::new(), | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
20 | impl Config { | 41 | impl 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?; |