Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active November 7, 2021 16:42
Show Gist options
  • Select an option

  • Save jayhuang75/cb5ff1e5f4c87478b614b9c4bb61269b to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/cb5ff1e5f4c87478b614b9c4bb61269b to your computer and use it in GitHub Desktop.
go train delay rust api srv init
#[allow(dead_code)]
pub struct Application {
port: u16,
server: Server,
}
impl Application {
pub async fn new() -> Result<Self, AppError> {
dotenv().ok();
let app_state = AppState::new().await?;
let srv = app_state.get_srv().await?;
Ok(Application {
port: 8080,
server: srv,
})
}
#[allow(dead_code)]
pub fn port(&self) -> u16 {
self.port
}
pub async fn run_until_stopped(self) -> Result<(), AppError> {
self.server.await?;
Ok(())
}
#[allow(dead_code)]
pub async fn graceful_shutdown(self) -> Result<(), AppError> {
self.server.stop(true).await;
Ok(())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment