feat: add shutdown url
This commit is contained in:
parent
d37f178ddd
commit
3473adabbc
|
@ -1,7 +1,7 @@
|
|||
version: "3.9"
|
||||
services:
|
||||
fiber-application:
|
||||
restart: always
|
||||
restart: on-failure
|
||||
image: docker-mariadb-clean-arch:latest
|
||||
build:
|
||||
context: .
|
||||
|
@ -10,6 +10,7 @@ services:
|
|||
ports:
|
||||
- 8080:8080
|
||||
environment:
|
||||
- ENV=prod
|
||||
- API_USERID=1
|
||||
- API_USERNAME=fiber
|
||||
- API_PASSWORD=fiber
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package misc
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Create a handler. Leave this empty, as we have no domains nor use-cases.
|
||||
type MiscHandler struct{}
|
||||
|
@ -11,6 +15,7 @@ func NewMiscHandler(miscRoute fiber.Router) {
|
|||
|
||||
// Declare routing.
|
||||
miscRoute.Get("", handler.healthCheck)
|
||||
miscRoute.Get("/shutdown", handler.shutdown)
|
||||
}
|
||||
|
||||
// Check for the health of the API.
|
||||
|
@ -20,3 +25,14 @@ func (h *MiscHandler) healthCheck(c *fiber.Ctx) error {
|
|||
"message": "Hello World!",
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MiscHandler) shutdown(ctx *fiber.Ctx) error {
|
||||
go func() {
|
||||
time.Sleep(1 * time.Second)
|
||||
os.Exit(0)
|
||||
}()
|
||||
return ctx.Status(fiber.StatusOK).JSON(&fiber.Map{
|
||||
"status": "success",
|
||||
"message": "server shutdown",
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user