findpenguins-feed/src/main.rs

49 lines
1.2 KiB
Rust

use std::net::SocketAddr;
use crate::{config::PenguinConfig, feeds::enrich_feeds};
mod app;
mod config;
mod css_handler;
mod feeds;
mod hash;
mod logging;
mod routes;
mod scrapers;
mod signals;
mod templates;
#[tokio::main]
async fn main() {
logging::setup("findpenguins_feed");
let config = PenguinConfig::read().expect("Failed to read application configuration");
let addr = get_addr(&config);
let feeds = enrich_feeds(config.feeds).await;
let app = app::create(feeds);
tracing::debug!("Listening on {}", addr);
let listener = tokio::net::TcpListener::bind(&addr)
.await
.expect("Faileds to listen on the specified address");
axum::serve(listener, app.into_make_service())
.with_graceful_shutdown(signals::shutdown())
.await
.expect("Failed to start server");
}
/// Retrieve the address to listen on.
///
/// # Returns
///
/// A `SocketAddr` object that represents the address to listen on.
///
/// # Panics
///
/// If the `host` string cannot be parsed into a `SocketAddr` object.
fn get_addr(config: &PenguinConfig) -> SocketAddr {
config
.server_address
.parse()
.expect("No proper address to listen on: {}")
}