-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: collect all options in the Options struct (#114)
- Loading branch information
Showing
9 changed files
with
119 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod watcher; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::net::IpAddr; | ||
|
||
use local_ip_address::local_ip; | ||
use tokio::net::TcpListener; | ||
|
||
use crate::ADDR; | ||
|
||
pub(crate) async fn create_listener(addr: String) -> Result<TcpListener, String> { | ||
match tokio::net::TcpListener::bind(&addr).await { | ||
Ok(listener) => { | ||
let port = listener.local_addr().unwrap().port(); | ||
let host = listener.local_addr().unwrap().ip(); | ||
let host = match host.is_unspecified() { | ||
true => match local_ip() { | ||
Ok(addr) => addr, | ||
Err(err) => { | ||
log::warn!("Failed to get local IP address: {}", err); | ||
host | ||
} | ||
}, | ||
false => host, | ||
}; | ||
|
||
let addr = match host { | ||
IpAddr::V4(host) => format!("{host}:{port}"), | ||
IpAddr::V6(host) => format!("[{host}]:{port}"), | ||
}; | ||
log::info!("Listening on http://{addr}/"); | ||
ADDR.set(addr).unwrap(); | ||
Ok(listener) | ||
} | ||
Err(err) => { | ||
let err_msg = if let std::io::ErrorKind::AddrInUse = err.kind() { | ||
format!("Address {} is already in use", &addr) | ||
} else { | ||
format!("Failed to listen on {}: {}", addr, err) | ||
}; | ||
log::error!("{err_msg}"); | ||
Err(err_msg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub(crate) mod listener; | ||
pub(crate) mod server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.