mirror of
https://github.com/SphericalKat/medium.rip.git
synced 2026-10-21 01:34:22 +00:00
feat: add shutdown listener
Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
1 parent
244804fe85
commit
219d16ea19
6 files changed
+132
-7
No files matched your search
+30
-3
@@ -1,9 +1,21 @@
|
||||
package api
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
func RegisterRoutes() {
|
||||
"github.com/medium.rip/internal/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func RegisterRoutes(ctx context.Context, wg *sync.WaitGroup) {
|
||||
app := fiber.New(fiber.Config{
|
||||
StreamRequestBody: true,
|
||||
ServerHeader: "Katbox",
|
||||
AppName: "Katbox",
|
||||
DisableStartupMessage: true,
|
||||
})
|
||||
|
||||
@@ -11,5 +23,20 @@ func RegisterRoutes() {
|
||||
return c.SendString("OK")
|
||||
})
|
||||
|
||||
app.Listen(":3000")
|
||||
go func(app *fiber.App) {
|
||||
log.Printf("Starting http server at: http://localhost:%s", config.Conf.Port)
|
||||
if err := app.Listen(fmt.Sprintf(":%s", config.Conf.Port)); err != nil {
|
||||
log.Fatalf("Unable to start http server: %s", err)
|
||||
}
|
||||
}(app)
|
||||
|
||||
// listen for context cancellation
|
||||
<-ctx.Done()
|
||||
|
||||
// shut down http server
|
||||
log.Info("Gracefully shutting down http server...")
|
||||
if err := app.Shutdown(); err != nil {
|
||||
log.Warn("Server shutdown Failed: ", err)
|
||||
}
|
||||
wg.Done()
|
||||
}
|
||||
Reference in new issue
Block a user