Skip to content

Commit

Permalink
use static client
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Hassan committed Jan 19, 2024
1 parent fde0f3f commit b724d9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ async fn main() {

let args = parse_cli_args();

let mut config_path = "/etc/telelog.toml";
match args.get_one::<PathBuf>("config") {
Some(path) => config_path = path.to_str().unwrap(),
None => println!("[main] Config file not specified, using '/etc/telelog.toml'"),
}
let config_path = match args.get_one::<PathBuf>("config") {
Some(path) => path.to_str().unwrap(),
None => {
println!("[main] Config file not specified, using '/etc/telelog.toml'");
"/etc/telelog.toml"
},
};

let settings = match read_config(config_path) {
Ok(settings) => settings,
Expand Down
4 changes: 2 additions & 2 deletions src/telegram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::config::AppSettings;
lazy_static!(
static ref LOG_BUFFER: AsyncMutex<Vec<LogEntry>> = AsyncMutex::new(vec![]);
static ref APP_SETTINGS_COPY: AsyncMutex<AppSettings> = AsyncMutex::new(AppSettings::default());
static ref CLIENT: reqwest::Client = reqwest::Client::new();
);

pub async fn init(settings: AppSettings) {
Expand Down Expand Up @@ -93,8 +94,7 @@ async fn flush_log_buffer() {
let api_key = (settings.telegram.api_key.as_ref().unwrap()).to_owned();
drop(settings);

let client = reqwest::Client::new();
match client.post(&format!("https://api.telegram.org/bot{}/sendMessage", api_key))
match CLIENT.post(&format!("https://api.telegram.org/bot{}/sendMessage", api_key))
.form(&[("chat_id", chat_id), ("text", message), ("parse_mode", "HTML".to_string())])
.send()
.await {
Expand Down

0 comments on commit b724d9d

Please sign in to comment.