From da27604fa29d4b98d2ca485cfab5ade0e4d318d6 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Fri, 22 Sep 2023 13:31:38 +0200 Subject: [PATCH] added status handler, so readyness+liveness-probes in k82 get some --- api/server.go | 10 +++++++--- api/status_handlers.go | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 api/status_handlers.go diff --git a/api/server.go b/api/server.go index e6d3ab0..12002a3 100644 --- a/api/server.go +++ b/api/server.go @@ -18,6 +18,7 @@ package api import ( "errors" + "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/compress" "github.com/gofiber/fiber/v2/middleware/cors" @@ -130,6 +131,9 @@ func Runserver(conf *cfg.Config, args []string) error { return FormPage(c, conf, db, shallExpire) }) + router.Get("/status", func(c *fiber.Ctx) error { + return Status(c, conf) + }) } // setup cleaner @@ -196,8 +200,8 @@ func SetupServer(conf *cfg.Config) *fiber.App { } /* - Wrapper to respond with proper json status, message and code, - shall be prepared and called by the handlers directly. +Wrapper to respond with proper json status, message and code, +shall be prepared and called by the handlers directly. */ func JsonStatus(c *fiber.Ctx, code int, msg string) error { success := true @@ -214,7 +218,7 @@ func JsonStatus(c *fiber.Ctx, code int, msg string) error { } /* - Used for non json-aware handlers, called by server +Used for non json-aware handlers, called by server */ func SendResponse(c *fiber.Ctx, msg string, err error) error { if err != nil { diff --git a/api/status_handlers.go b/api/status_handlers.go new file mode 100644 index 0000000..03d5395 --- /dev/null +++ b/api/status_handlers.go @@ -0,0 +1,24 @@ +/* +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +package api + +import ( + "github.com/gofiber/fiber/v2" + "github.com/tlinden/ephemerup/cfg" + "github.com/tlinden/ephemerup/common" +) + +func Status(c *fiber.Ctx, cfg *cfg.Config) error { + res := &common.Response{} + res.Success = true + res.Code = fiber.StatusOK + res.Message = "up and running" + return c.Status(fiber.StatusOK).JSON(res) +}