rill_server/
config.rs

1//! The module contains all configuration structs for the embedded node.
2
3use rill_protocol::config::ConfigPatch;
4use serde::Deserialize;
5use std::net::IpAddr;
6
7/// Overrides default embedded server address.
8pub static SERVER_ADDRESS: ConfigPatch<IpAddr> = ConfigPatch::new("RILLRATE_SERVER_ADDRESS");
9
10/// Embedded server configuration.
11#[derive(Deserialize, Debug)]
12pub struct ServerConfig {
13    /// An address where bind the server.
14    pub address: Option<IpAddr>,
15}
16
17impl Default for ServerConfig {
18    fn default() -> Self {
19        Self { address: None }
20    }
21}
22
23impl ServerConfig {
24    /// Returns address where bind a server
25    pub fn server_address(&self) -> IpAddr {
26        SERVER_ADDRESS.get(|| self.address, || "127.0.0.1".parse().unwrap())
27    }
28}