add logging to online
Signed-off-by: Odyssey <odyssey346@disroot.org>
This commit is contained in:
parent
fffd28165b
commit
93353c7551
7
main.go
7
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ProjectSegfault/publapi/pages"
|
"github.com/ProjectSegfault/publapi/pages"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// publapi is a simple API for Project Segfault's public shared server (pubnix).
|
// 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 {
|
app.Get("/online", func(c *fiber.Ctx) error {
|
||||||
|
|
||||||
|
// set up logger
|
||||||
|
logger, _ := zap.NewProduction()
|
||||||
|
defer logger.Sync()
|
||||||
|
|
||||||
// Get the number of users online
|
// Get the number of users online
|
||||||
out, err := exec.Command("users | wc -l").Output()
|
out, err := exec.Command("users | wc -l").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Error("failed to get number of users online", zap.Error(err))
|
||||||
return c.SendStatus(fiber.StatusInternalServerError)
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user