Add version API

Signed-off-by: Odyssey <odyssey346@disroot.org>
This commit is contained in:
Odyssey
2023-01-05 20:35:31 +01:00
parent 02325162a8
commit 30014eadb0
+24
View File
@@ -7,6 +7,8 @@ import (
"html/template"
"log"
"os"
"runtime"
"runtime/debug"
"time"
"codeberg.org/gothub/gothub/pages"
@@ -169,6 +171,28 @@ func Serve() {
c.Response().Header.Del(fiber.HeaderServer)
return nil
})
api := app.Group("/api")
v1 := api.Group("/v1")
v1.Get("/version", func(c *fiber.Ctx) error {
// taken from https://git.vern.cc/pjals/bestofbot.
var Version = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value[:8]
}
}
}
return "unknown"
}()
return c.JSON(fiber.Map{
"version": Version,
"fiberversion": fiber.Version,
"goversion": runtime.Version(),
})
})
val, ok := os.LookupEnv("GOTHUB_PORT")
if !ok {
val = "3000"