add logging to online

Signed-off-by: Odyssey <odyssey346@disroot.org>
This commit is contained in:
Odyssey 2023-01-07 17:48:15 +01:00
parent fffd28165b
commit 93353c7551

View File

@ -6,6 +6,7 @@ import (
"github.com/ProjectSegfault/publapi/pages"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
)
// publapi is a simple API for Project Segfault's public shared server (pubnix).
@ -20,9 +21,15 @@ func main() {
})
app.Get("/online", func(c *fiber.Ctx) error {
// set up logger
logger, _ := zap.NewProduction()
defer logger.Sync()
// Get the number of users online
out, err := exec.Command("users | wc -l").Output()
if err != nil {
logger.Error("failed to get number of users online", zap.Error(err))
return c.SendStatus(fiber.StatusInternalServerError)
}