Files
gatus/controller/controller.go
T

49 lines
1.1 KiB
Go
Raw Normal View History

2020-12-29 20:22:17 -05:00
package controller
import (
"os"
2020-12-29 20:22:17 -05:00
"time"
"github.com/TwiN/gatus/v5/api"
2022-12-06 01:41:09 -05:00
"github.com/TwiN/gatus/v5/config"
"github.com/TwiN/logr"
"github.com/gofiber/fiber/v2"
2020-12-29 20:22:17 -05:00
)
var (
app *fiber.App
2020-12-29 20:22:17 -05:00
)
// Handle creates the router and starts the server
func Handle(cfg *config.Config) {
api := api.New(cfg)
app = api.Router()
server := app.Server()
server.ReadTimeout = 15 * time.Second
server.WriteTimeout = 15 * time.Second
server.IdleTimeout = 15 * time.Second
2021-02-01 01:37:56 -05:00
if os.Getenv("ROUTER_TEST") == "true" {
return
}
logr.Info("[controller.Handle] Listening on " + cfg.Web.SocketAddress())
if cfg.Web.HasTLS() {
err := app.ListenTLS(cfg.Web.SocketAddress(), cfg.Web.TLS.CertificateFile, cfg.Web.TLS.PrivateKeyFile)
if err != nil {
logr.Fatalf("[controller.Handle] %s", err.Error())
}
2023-04-22 18:12:56 +02:00
} else {
err := app.Listen(cfg.Web.SocketAddress())
if err != nil {
logr.Fatalf("[controller.Handle] %s", err.Error())
}
2023-04-22 18:12:56 +02:00
}
logr.Info("[controller.Handle] Server has shut down successfully")
2021-02-05 20:45:28 -05:00
}
// Shutdown stops the server
func Shutdown() {
if app != nil {
_ = app.Shutdown()
app = nil
2021-02-05 20:45:28 -05:00
}
2020-12-29 20:22:17 -05:00
}