2023-05-26 14:12:53 +00:00
|
|
|
package api
|
|
|
|
|
2023-05-26 14:20:40 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
2023-05-26 14:12:53 +00:00
|
|
|
|
2023-05-26 14:20:40 +00:00
|
|
|
"github.com/medium.rip/internal/config"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RegisterRoutes(ctx context.Context, wg *sync.WaitGroup) {
|
2023-05-26 14:12:53 +00:00
|
|
|
app := fiber.New(fiber.Config{
|
2023-05-26 14:20:40 +00:00
|
|
|
StreamRequestBody: true,
|
|
|
|
ServerHeader: "Katbox",
|
|
|
|
AppName: "Katbox",
|
2023-05-26 14:12:53 +00:00
|
|
|
DisableStartupMessage: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
app.Get("/", func(c *fiber.Ctx) error {
|
|
|
|
return c.SendString("OK")
|
|
|
|
})
|
|
|
|
|
2023-05-26 14:20:40 +00:00
|
|
|
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()
|
2023-05-26 14:12:53 +00:00
|
|
|
}
|