Parent [>]
1//! Global application configuration set once at startup.
2//!
3//! Values are stored in `OnceLock` statics and accessed via the corresponding
4//! getter functions.  All setters accept `Option` and silently skip `None`.
5
6use std::sync::OnceLock;
7
8pub const PKG_NAME: &str = env!("CARGO_PKG_NAME");
9pub const PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
10
11static HOSTNAME: OnceLock<String> = OnceLock::new();
12static SSH_PREFIX: OnceLock<String> = OnceLock::new();
13static BASE_URL: OnceLock<String> = OnceLock::new();
14static FAVICON: OnceLock<Vec<u8>> = OnceLock::new();
15
16/// Returns the configured hostname, or `"index"` if none was provided.
17pub fn hostname() -> &'static str {
18    HOSTNAME.get().map_or("index", |s| s.as_str())
19}
20
21/// Returns the configured SSH prefix, or an empty string if none was provided.
22pub fn ssh_prefix() -> &'static str {
23    SSH_PREFIX.get().map_or("", |s| s.as_str())
24}
25
26/// Returns the configured base URL path prefix, or an empty string if none was
27/// provided.
28pub fn base_url() -> &'static str {
29    BASE_URL.get().map_or("", |s| s.as_str())
30}
31
32/// Returns the favicon bytes loaded at startup.
33pub fn favicon() -> &'static [u8] {
34    FAVICON.get().map_or(&[], |v| v.as_slice())
35}
36
37pub fn set_hostname(v: Option<String>) {
38    if let Some(v) = v {
39        let _ = HOSTNAME.set(v);
40    }
41}
42
43pub fn set_ssh_prefix(v: Option<String>) {
44    if let Some(v) = v {
45        let _ = SSH_PREFIX.set(v);
46    }
47}
48
49pub fn set_base_url(v: Option<String>) {
50    if let Some(v) = v {
51        let _ = BASE_URL.set(v);
52    }
53}
54
55pub fn set_favicon(v: Vec<u8>) {
56    let _ = FAVICON.set(v);
57}