Skip to content

Commit

Permalink
changes in config
Browse files Browse the repository at this point in the history
  • Loading branch information
annikahannig committed Oct 30, 2024
1 parent de87c18 commit 9a434c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
22 changes: 10 additions & 12 deletions src/api/server.rs
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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(())
}
2 changes: 0 additions & 2 deletions src/api/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ use anyhow::Result;
use crate::{
api::{responses::StatusResponse, Error},
bird::Birdc,
state::ApiStatus,
};

/// Get the current status
pub async fn retrieve() -> Result<String, Error> {
let birdc = Birdc::default();
let status = birdc.show_status().await?;
let response = StatusResponse {
api: ApiStatus::default(),
status,
..Default::default()
};
Expand Down
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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<()> {
Expand All @@ -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(())
}

0 comments on commit 9a434c4

Please sign in to comment.