pub struct Server { /* private fields */ }Expand description
Represents the high-level server controller responsible for loading configuration, applying custom setup, and running the application.
This structure encapsulates CLI arguments, server settings, and an optional configuration callback for the Actix-Web service.
Implementations§
Source§impl Server
impl Server
Sourcepub fn global_server() -> Option<&'static Server>
pub fn global_server() -> Option<&'static Server>
Returns a reference to the globally initialized Server, if it exists.
This function provides access to the global server instance managed
through the GlobalServer trait.
§Examples
use rust_microservice::Server;
let server = Server::global_server();Sourcepub fn set_global(server: Server)
pub fn set_global(server: Server)
Sourcepub fn new(app_version: String, banner: Option<String>) -> Self
pub fn new(app_version: String, banner: Option<String>) -> Self
Creates a new empty Server instance with no configuration loaded.
Useful as the starting point for building and initializing the server lifecycle.
pub async fn new_with_settings(settings: Settings) -> Result<Self>
Sourcepub async fn init(self) -> Result<Self>
pub async fn init(self) -> Result<Self>
Loads CLI arguments and resolves the application configuration.
This method parses command-line arguments, attempts to load the
server settings, and stores both inside the Server instance.
Panics if configuration loading fails.
§Returns
The updated Server instance.
Sourcepub fn configure(self, fnconfig: Option<fn(&mut ServiceConfig)>) -> Self
pub fn configure(self, fnconfig: Option<fn(&mut ServiceConfig)>) -> Self
Sourcepub async fn intialize_database(self) -> Result<Self>
pub async fn intialize_database(self) -> Result<Self>
Initializes the database connections using the previously loaded settings.
This method creates and initializes all required database connections, including the BigQuery client, based on the application settings. It must be called after the settings have been loaded.
§Behavior
- Validates that the application settings are available.
- Instantiates the
ServerDatabaseusing the provided settings. - Stores the initialized database instance in the application state.
- Retrieves and logs the list of available BigQuery tables.
§Panics
This method will panic if:
- The settings have not been loaded before calling this method.
§Returns
Returns Self with the database field initialized.
§Example
use rust_microservice::Server;
async fn start_server() -> rust_microservice::Result<(), String> {
let server = Server::new("0.1.3".to_string(), None)
.init()
.await
.map_err(|e|e.to_string())?
.intialize_database()
.await
.map_err(|e|e.to_string())?;
Ok(())
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Server
impl !RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
impl !UnwindSafe for Server
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request