jax_daemon/http_server/
config.rs1use std::net::SocketAddr;
2
3use url::Url;
4
5#[derive(Debug, Clone)]
6pub struct Config {
7 pub listen_addr: SocketAddr,
9 #[allow(unused)]
13 pub hostname: Url,
14 pub log_level: tracing::Level,
16 #[allow(unused)]
18 pub gateway_url: Option<String>,
19}
20
21impl Config {
22 pub fn new(listen_addr: SocketAddr, gateway_url: Option<String>) -> Self {
23 let hostname = Url::parse(&format!("http://localhost:{}", listen_addr.port())).unwrap();
24 tracing::info!(
25 "Creating HTTP server Config: listen_addr={}, gateway_url={:?}",
26 listen_addr,
27 gateway_url
28 );
29 Self {
30 listen_addr,
31 hostname,
32 log_level: tracing::Level::INFO,
33 gateway_url,
34 }
35 }
36}
37
38#[allow(dead_code)]
39#[derive(Debug, thiserror::Error)]
40pub enum ConfigError {
41 #[error("Invalid URL: {0}")]
42 Url(#[from] url::ParseError),
43 #[error("Invalid Socket Address: {0}")]
44 ListenAddr(#[from] std::net::AddrParseError),
45}