Last active
November 7, 2021 16:42
-
-
Save jayhuang75/cb5ff1e5f4c87478b614b9c4bb61269b to your computer and use it in GitHub Desktop.
go train delay rust api srv init
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[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