Add option to add port to listen on
This commit is contained in:
parent
9d0f35db70
commit
c3c5ff4ebe
@ -7,5 +7,5 @@ There is also a Map: <https://www.berlinerbaeder.de/baeder/sommerbaeder-auslastu
|
||||
## Run
|
||||
|
||||
```
|
||||
berlinerbaeder-exporter
|
||||
berlinerbaeder-exporter --listen "[::]:1234"
|
||||
```
|
||||
|
26
src/main.rs
26
src/main.rs
@ -29,11 +29,35 @@ struct TrafficDataItem {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
||||
let mut args = std::env::args();
|
||||
let _name = args.next().unwrap();
|
||||
|
||||
let mut listen = String::from("[::]:3000");
|
||||
|
||||
loop {
|
||||
let arg = if let Some(arg) = args.next() {
|
||||
arg
|
||||
} else {
|
||||
break;
|
||||
};
|
||||
|
||||
match arg.as_str() {
|
||||
"--listen" => {
|
||||
listen = args.next().unwrap();
|
||||
}
|
||||
unknown => {
|
||||
println!("unknown option: {}", unknown);
|
||||
std::process::exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(route_index))
|
||||
.route("/metrics", get(route_metrics));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("[::]:3000").await.unwrap();
|
||||
let listener = tokio::net::TcpListener::bind(listen).await.unwrap();
|
||||
println!("Server listening on: http://{}", listener.local_addr().unwrap());
|
||||
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user