mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-25 09:24:04 +01:00
6bb65f4eec
Fixes #468
44 lines
924 B
Go
44 lines
924 B
Go
package controller
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/TwiN/gatus/v5/api"
|
|
"github.com/TwiN/gatus/v5/config"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
var (
|
|
app *fiber.App
|
|
)
|
|
|
|
// 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
|
|
server.TLSConfig = cfg.Web.TLSConfig()
|
|
if os.Getenv("ROUTER_TEST") == "true" {
|
|
return
|
|
}
|
|
log.Println("[controller][Handle] Listening on " + cfg.Web.SocketAddress())
|
|
if server.TLSConfig != nil {
|
|
log.Println("[controller][Handle]", app.ListenTLS(cfg.Web.SocketAddress(), "", ""))
|
|
} else {
|
|
log.Println("[controller][Handle]", app.Listen(cfg.Web.SocketAddress()))
|
|
}
|
|
}
|
|
|
|
// Shutdown stops the server
|
|
func Shutdown() {
|
|
if app != nil {
|
|
_ = app.Shutdown()
|
|
app = nil
|
|
}
|
|
}
|