diff --git a/src/api/server.rs b/src/api/server.rs index e3f9ac3..e33d36c 100644 --- a/src/api/server.rs +++ b/src/api/server.rs @@ -1,23 +1,21 @@ use anyhow::Result; use axum::{routing::get, Router}; use tower_http::trace::TraceLayer; +use tokio::net::TcpListener; -use crate::api::{neighbors, status, tables}; +use crate::{ + config, + api::{neighbors, status, tables}, +}; -/// Server Options -#[derive(Default, Debug)] -pub struct Opts { - /// Server listen address - pub listen: String, -} /// Get the welcome message -async fn welcome() -> &'static str { - "lightwatcher v0.0.1" +async fn welcome() -> String { + format!("lightwatcher {}", crate::version()) } /// Start the API http server -pub async fn start(opts: &Opts) -> Result<()> { +pub async fn start() -> Result<()> { let app = Router::new() .route("/", get(welcome)) .route("/status", get(status::retrieve)) @@ -41,8 +39,8 @@ pub async fn start(opts: &Opts) -> Result<()> { ) .layer(TraceLayer::new_for_http()); - let listener = tokio::net::TcpListener::bind(&opts.listen).await?; + let listen = config::get_listen_address(); + let listener = TcpListener::bind(&listen).await?; axum::serve(listener, app).await?; - Ok(()) } diff --git a/src/api/status.rs b/src/api/status.rs index 0acf685..f23bca2 100644 --- a/src/api/status.rs +++ b/src/api/status.rs @@ -3,7 +3,6 @@ use anyhow::Result; use crate::{ api::{responses::StatusResponse, Error}, bird::Birdc, - state::ApiStatus, }; /// Get the current status @@ -11,7 +10,6 @@ pub async fn retrieve() -> Result { let birdc = Birdc::default(); let status = birdc.show_status().await?; let response = StatusResponse { - api: ApiStatus::default(), status, ..Default::default() }; diff --git a/src/main.rs b/src/main.rs index 847dfe4..ea7cfc1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ use anyhow::Result; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; -use lightwatcher::api::{self, server::Opts}; -use lightwatcher::config; +use lightwatcher::{api, config}; #[tokio::main] async fn main() -> Result<()> { @@ -24,8 +23,6 @@ async fn main() -> Result<()> { tracing::info!(LIGHTWATCHER_BIRDC = config::get_birdc_socket(), "env"); // Start API server - let listen = config::get_listen_address(); - api::server::start(&Opts { listen }).await?; - + api::server::start().await?; Ok(()) }