aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-03-04 21:59:50 +0100
committerFxQnLr <[email protected]>2024-03-04 21:59:50 +0100
commit85c63c2ca8448428e2db93cb9d4f284a4e314ed7 (patch)
tree0180a452dd354b067470618e6dbdc330649287cb /src
parent0a058ba2064d323451462a79c71580dea7d8ec8c (diff)
downloadwebol-85c63c2ca8448428e2db93cb9d4f284a4e314ed7.tar
webol-85c63c2ca8448428e2db93cb9d4f284a4e314ed7.tar.gz
webol-85c63c2ca8448428e2db93cb9d4f284a4e314ed7.zip
#20. Set offset manually through config
Diffstat (limited to 'src')
-rw-r--r--src/config.rs2
-rw-r--r--src/main.rs11
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
13impl Config { 14impl 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};
12use dashmap::DashMap; 12use dashmap::DashMap;
13use sqlx::PgPool; 13use sqlx::PgPool;
14use time::UtcOffset;
14use std::{env, sync::Arc}; 15use std::{env, sync::Arc};
15use tokio::sync::broadcast::{channel, Sender}; 16use tokio::sync::broadcast::{channel, Sender};
16use tracing::{info, level_filters::LevelFilter}; 17use tracing::{info, level_filters::LevelFilter};
17use tracing_subscriber::{ 18use 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 {
77async fn main() -> color_eyre::eyre::Result<()> { 78async 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;