forked from Finb/bark-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_misc.go
39 lines (34 loc) · 946 Bytes
/
route_misc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"runtime"
"time"
"github.com/gofiber/fiber/v2"
)
func init() {
registerRoute("misc", func(router fiber.Router) {
// ping func only returns a "pong" string, usually used to test server response
router.Get("/ping", func(c *fiber.Ctx) error {
return c.JSON(CommonResp{
Code: 200,
Message: "pong",
Timestamp: time.Now().Unix(),
})
})
// healthz func only returns a "ok" string, similar to ping func,
// healthz func is usually used for health check
router.Get("/healthz", func(c *fiber.Ctx) error {
return c.SendString("ok")
})
// info func returns information about the server version
router.Get("/info", func(c *fiber.Ctx) error {
devices, _ := db.CountAll()
return c.JSON(map[string]interface{}{
"version": version,
"build": buildDate,
"arch": runtime.GOOS + "/" + runtime.GOARCH,
"commit": commitID,
"devices": devices,
})
})
})
}