diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs index 58043c2..9605361 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -8,6 +8,7 @@ pub struct Config { | |||
8 | pub serveraddr: String, | 8 | pub serveraddr: String, |
9 | pub pingtimeout: i64, | 9 | pub pingtimeout: i64, |
10 | pub pingthreshold: i64, | 10 | pub pingthreshold: i64, |
11 | pub timeoffset: i8, | ||
11 | } | 12 | } |
12 | 13 | ||
13 | impl Config { | 14 | impl Config { |
@@ -16,6 +17,7 @@ impl Config { | |||
16 | .set_default("serveraddr", "0.0.0.0:7229")? | 17 | .set_default("serveraddr", "0.0.0.0:7229")? |
17 | .set_default("pingtimeout", 10)? | 18 | .set_default("pingtimeout", 10)? |
18 | .set_default("pingthreshold", 1)? | 19 | .set_default("pingthreshold", 1)? |
20 | .set_default("timeoffset", 0)? | ||
19 | .add_source(File::with_name("config.toml").required(false)) | 21 | .add_source(File::with_name("config.toml").required(false)) |
20 | .add_source(File::with_name("config.dev.toml").required(false)) | 22 | .add_source(File::with_name("config.dev.toml").required(false)) |
21 | .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_")) | 23 | .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_")) |
diff --git a/src/main.rs b/src/main.rs index 8978e58..00fc6ce 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -11,11 +11,12 @@ use axum::{ | |||
11 | }; | 11 | }; |
12 | use dashmap::DashMap; | 12 | use dashmap::DashMap; |
13 | use sqlx::PgPool; | 13 | use sqlx::PgPool; |
14 | use time::UtcOffset; | ||
14 | use std::{env, sync::Arc}; | 15 | use std::{env, sync::Arc}; |
15 | use tokio::sync::broadcast::{channel, Sender}; | 16 | use tokio::sync::broadcast::{channel, Sender}; |
16 | use tracing::{info, level_filters::LevelFilter}; | 17 | use tracing::{info, level_filters::LevelFilter}; |
17 | use tracing_subscriber::{ | 18 | use tracing_subscriber::{ |
18 | fmt::{self, time::UtcTime}, | 19 | fmt::{self, time::OffsetTime}, |
19 | prelude::*, | 20 | prelude::*, |
20 | EnvFilter, | 21 | EnvFilter, |
21 | }; | 22 | }; |
@@ -77,16 +78,18 @@ impl Modify for SecurityAddon { | |||
77 | async fn main() -> color_eyre::eyre::Result<()> { | 78 | async fn main() -> color_eyre::eyre::Result<()> { |
78 | color_eyre::install()?; | 79 | color_eyre::install()?; |
79 | 80 | ||
81 | let config = Config::load()?; | ||
82 | |||
80 | let time_format = | 83 | let time_format = |
81 | time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); | 84 | time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); |
82 | let loc = UtcTime::new(time_format); | 85 | let time = OffsetTime::new(UtcOffset::from_hms(config.timeoffset, 0, 0)?, time_format); |
83 | 86 | ||
84 | let file_appender = tracing_appender::rolling::daily("logs", "webol.log"); | 87 | let file_appender = tracing_appender::rolling::daily("logs", "webol.log"); |
85 | let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); | 88 | let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); |
86 | 89 | ||
87 | tracing_subscriber::registry() | 90 | tracing_subscriber::registry() |
88 | .with(fmt::layer().with_writer(non_blocking).with_ansi(false)) | 91 | .with(fmt::layer().with_writer(non_blocking).with_ansi(false)) |
89 | .with(fmt::layer().with_timer(loc)) | 92 | .with(fmt::layer().with_timer(time)) |
90 | .with( | 93 | .with( |
91 | EnvFilter::builder() | 94 | EnvFilter::builder() |
92 | .with_default_directive(LevelFilter::INFO.into()) | 95 | .with_default_directive(LevelFilter::INFO.into()) |
@@ -96,8 +99,6 @@ async fn main() -> color_eyre::eyre::Result<()> { | |||
96 | 99 | ||
97 | let version = env!("CARGO_PKG_VERSION"); | 100 | let version = env!("CARGO_PKG_VERSION"); |
98 | 101 | ||
99 | let config = Config::load()?; | ||
100 | |||
101 | info!("start webol v{}", version); | 102 | info!("start webol v{}", version); |
102 | 103 | ||
103 | let db = init_db_pool(&config.database_url).await; | 104 | let db = init_db_pool(&config.database_url).await; |