Skip to main content

jax_daemon/http_server/
config.rs

1use std::net::SocketAddr;
2
3use url::Url;
4
5#[derive(Debug, Clone)]
6pub struct Config {
7    // Listen address
8    pub listen_addr: SocketAddr,
9    // TODO (amiller68): at some point we will use this to
10    //  support showings links to objects within a bucket
11    // Host name for generating content URLs
12    #[allow(unused)]
13    pub hostname: Url,
14    // log level for http tracing
15    pub log_level: tracing::Level,
16    // External gateway URL for generating share/download links
17    #[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}