File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -51,5 +51,8 @@ func main() {
51
51
}()
52
52
}
53
53
54
- app .NewApp (context .Background (), cfg ).Run ()
54
+ if err := app .NewApp (context .Background (), cfg ).Run (); err != nil {
55
+ log .Print ("Unable to start app" )
56
+ return
57
+ }
55
58
}
Original file line number Diff line number Diff line change @@ -49,14 +49,33 @@ func (app *App) Run() error {
49
49
<- quit
50
50
log .Info ("Server is shutting down..." )
51
51
52
- // Create a context with a timeout of 10 seconds for the server shutdown.
52
+ // Create a context with a timeout to ensure graceful shutdown
53
53
ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
54
54
defer cancel ()
55
55
56
- // Shutdown gracefully.
57
- app .db .DB .Close ()
58
- app .echo .Shutdown (ctx )
56
+ // Attempt to gracefully shutdown the Echo server
57
+ if err := app .echo .Shutdown (ctx ); err != nil {
58
+ log .Errorf ("Server shutdown failed: %v" , err )
59
+ } else {
60
+ log .Info ("Server shutdown gracefully" )
61
+ }
62
+
63
+ // Close the database connection
64
+ if err := app .db .DB .Close (); err != nil {
65
+ log .Errorf ("Database connection close failed: %v" , err )
66
+ } else {
67
+ log .Info ("Database connection closed" )
68
+ }
59
69
}()
60
70
61
- return app .echo .Start (fmt .Sprintf (":%s" , app .cfg .Server .Port ))
71
+ // Start the Echo server
72
+ port := fmt .Sprintf (":%s" , app .cfg .Server .Port )
73
+ log .Infof ("Server is starting on port %s" , port )
74
+
75
+ if err := app .echo .Start (port ); err != nil {
76
+ log .Errorf ("Error starting server: %v" , err )
77
+ return err
78
+ }
79
+
80
+ return nil
62
81
}
You can’t perform that action at this time.
0 commit comments