mirror of
https://codeberg.org/icewind/prometheus-mdns-rs.git
synced 2026-06-03 09:54:21 +02:00
clippy
This commit is contained in:
parent
31062ff230
commit
8800649d36
2 changed files with 7 additions and 6 deletions
|
|
@ -7,6 +7,7 @@ description = "mDNS service discovery for prometherus"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/icewind1991/prometheus-mdns-rs"
|
repository = "https://github.com/icewind1991/prometheus-mdns-rs"
|
||||||
|
keywords = ["mdns", "prometheus"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mdns = { version = "0.3", git = "https://github.com/icewind1991/mdns", branch = "async_await" }
|
mdns = { version = "0.3", git = "https://github.com/icewind1991/mdns", branch = "async_await" }
|
||||||
|
|
|
||||||
12
src/main.rs
12
src/main.rs
|
|
@ -9,7 +9,7 @@ use std::time::Instant;
|
||||||
use std::{net::IpAddr, time::Duration};
|
use std::{net::IpAddr, time::Duration};
|
||||||
|
|
||||||
/// The hostname of the devices we are searching for.
|
/// The hostname of the devices we are searching for.
|
||||||
const SERVICE_NAME: &'static str = "_prometheus-http._tcp.local";
|
const SERVICE_NAME: &str = "_prometheus-http._tcp.local";
|
||||||
|
|
||||||
struct Service {
|
struct Service {
|
||||||
labels: HashMap<String, String>,
|
labels: HashMap<String, String>,
|
||||||
|
|
@ -36,11 +36,11 @@ impl<'a> From<&'a Service> for PrometheusService<'a> {
|
||||||
const TIMEOUT: Duration = Duration::from_secs(60);
|
const TIMEOUT: Duration = Duration::from_secs(60);
|
||||||
const INTERVAL: Duration = Duration::from_secs(15);
|
const INTERVAL: Duration = Duration::from_secs(15);
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), main_error::MainError> {
|
async fn main() -> Result<(), main_error::MainError> {
|
||||||
let out = env::args()
|
let out = env::args()
|
||||||
.skip(1)
|
.nth(1)
|
||||||
.next()
|
|
||||||
.map(|path| AtomicFile::new(path, AllowOverwrite));
|
.map(|path| AtomicFile::new(path, AllowOverwrite));
|
||||||
|
|
||||||
let stream = mdns::discover::all(SERVICE_NAME, INTERVAL)?.listen();
|
let stream = mdns::discover::all(SERVICE_NAME, INTERVAL)?.listen();
|
||||||
|
|
@ -49,9 +49,9 @@ async fn main() -> Result<(), main_error::MainError> {
|
||||||
let mut services: HashMap<IpAddr, Service> = HashMap::new();
|
let mut services: HashMap<IpAddr, Service> = HashMap::new();
|
||||||
|
|
||||||
while let Some(Ok(response)) = stream.next().await {
|
while let Some(Ok(response)) = stream.next().await {
|
||||||
let addr = response.records().filter_map(self::to_ip_addr).next();
|
let addr = response.records().find_map(self::to_ip_addr);
|
||||||
let port = response.records().filter_map(self::to_port).next();
|
let port = response.records().find_map(self::to_port);
|
||||||
let labels = response.records().filter_map(self::to_labels).next();
|
let labels = response.records().find_map(self::to_labels);
|
||||||
|
|
||||||
if let (Some(addr), Some(labels), Some(port)) = (addr, labels, port) {
|
if let (Some(addr), Some(labels), Some(port)) = (addr, labels, port) {
|
||||||
let service = Service {
|
let service = Service {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue