pub struct DashboardConfig {
pub bind_address: String,
pub port: u16,
pub database_url: String,
pub pool_size: u32,
pub static_dir: PathBuf,
pub auth: AuthConfig,
pub websocket: WebSocketConfig,
pub enable_cors: bool,
pub request_timeout: Duration,
}Expand description
Main configuration for the web dashboard.
This struct contains all configuration options for the Hammerwork web dashboard, including server settings, database connection, authentication, and WebSocket options.
§Examples
use hammerwork_web::config::DashboardConfig;
use std::path::PathBuf;
// Create with defaults
let config = DashboardConfig::default();
assert_eq!(config.bind_address, "127.0.0.1");
assert_eq!(config.port, 8080);
// Use builder pattern
let config = DashboardConfig::new()
.with_bind_address("0.0.0.0", 9090)
.with_database_url("postgresql://localhost/hammerwork")
.with_cors(true);
assert_eq!(config.bind_addr(), "0.0.0.0:9090");
assert!(config.enable_cors);Fields§
§bind_address: StringServer bind address
port: u16Server port
database_url: StringDatabase connection URL
pool_size: u32Database connection pool size
static_dir: PathBufDirectory containing static assets (HTML, CSS, JS)
auth: AuthConfigAuthentication configuration
websocket: WebSocketConfigWebSocket configuration
enable_cors: boolEnable CORS for cross-origin requests
request_timeout: DurationRequest timeout duration
Implementations§
Source§impl DashboardConfig
impl DashboardConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new configuration with defaults.
§Examples
use hammerwork_web::config::DashboardConfig;
let config = DashboardConfig::new();
assert_eq!(config.bind_address, "127.0.0.1");
assert_eq!(config.port, 8080);
assert_eq!(config.database_url, "postgresql://localhost/hammerwork");Sourcepub fn with_bind_address(self, address: &str, port: u16) -> Self
pub fn with_bind_address(self, address: &str, port: u16) -> Self
Set the server bind address and port.
§Examples
use hammerwork_web::config::DashboardConfig;
let config = DashboardConfig::new()
.with_bind_address("0.0.0.0", 9090);
assert_eq!(config.bind_address, "0.0.0.0");
assert_eq!(config.port, 9090);
assert_eq!(config.bind_addr(), "0.0.0.0:9090");Sourcepub fn with_database_url(self, url: &str) -> Self
pub fn with_database_url(self, url: &str) -> Self
Set the database URL.
Supports both PostgreSQL and MySQL database URLs.
§Examples
use hammerwork_web::config::DashboardConfig;
// PostgreSQL
let pg_config = DashboardConfig::new()
.with_database_url("postgresql://user:pass@localhost/hammerwork");
assert_eq!(pg_config.database_url, "postgresql://user:pass@localhost/hammerwork");
// MySQL
let mysql_config = DashboardConfig::new()
.with_database_url("mysql://root:password@localhost/hammerwork");
assert_eq!(mysql_config.database_url, "mysql://root:password@localhost/hammerwork");Sourcepub fn with_static_dir(self, dir: PathBuf) -> Self
pub fn with_static_dir(self, dir: PathBuf) -> Self
Set the static assets directory.
§Examples
use hammerwork_web::config::DashboardConfig;
use std::path::PathBuf;
let config = DashboardConfig::new()
.with_static_dir(PathBuf::from("/var/www/dashboard"));
assert_eq!(config.static_dir, PathBuf::from("/var/www/dashboard"));Sourcepub fn with_auth(self, username: &str, password_hash: &str) -> Self
pub fn with_auth(self, username: &str, password_hash: &str) -> Self
Enable authentication with username and password hash.
The password should be a bcrypt hash for security. When authentication is enabled, all API endpoints and WebSocket connections will require basic authentication.
§Examples
use hammerwork_web::config::DashboardConfig;
let config = DashboardConfig::new()
.with_auth("admin", "$2b$12$hash...");
assert!(config.auth.enabled);
assert_eq!(config.auth.username, "admin");
assert_eq!(config.auth.password_hash, "$2b$12$hash...");Sourcepub fn with_cors(self, enabled: bool) -> Self
pub fn with_cors(self, enabled: bool) -> Self
Enable or disable CORS support.
When enabled, the server will accept cross-origin requests from any domain. This is useful for development or when the dashboard is accessed from different domains.
§Examples
use hammerwork_web::config::DashboardConfig;
let config = DashboardConfig::new()
.with_cors(true);
assert!(config.enable_cors);
let config = DashboardConfig::new()
.with_cors(false);
assert!(!config.enable_cors);Sourcepub fn save_to_file(&self, path: &str) -> Result<()>
pub fn save_to_file(&self, path: &str) -> Result<()>
Save configuration to a TOML file
Trait Implementations§
Source§impl Clone for DashboardConfig
impl Clone for DashboardConfig
Source§fn clone(&self) -> DashboardConfig
fn clone(&self) -> DashboardConfig
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DashboardConfig
impl Debug for DashboardConfig
Source§impl Default for DashboardConfig
impl Default for DashboardConfig
Source§impl<'de> Deserialize<'de> for DashboardConfig
impl<'de> Deserialize<'de> for DashboardConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for DashboardConfig
impl RefUnwindSafe for DashboardConfig
impl Send for DashboardConfig
impl Sync for DashboardConfig
impl Unpin for DashboardConfig
impl UnwindSafe for DashboardConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more