feat: add shutdown listener

Signed-off-by: Sphericalkat <amolele@gmail.com>
This commit is contained in:
sphericalkat committed 2023-05-26 19:50:40 +05:30
1 parent 244804fe85
commit 219d16ea19
6 files changed
+132 -7

No files matched your search

+30 -3
View File
@@ -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()
}