golang-lib/web/api/status/main.go

52 lines
1.1 KiB
Go

package status
import (
"net/http"
"github.com/gin-gonic/gin"
"codeberg.org/genofire/golang-lib/web"
)
var (
// VERSION string on status API
VERSION string = ""
// UP function to detect, if API is healthy
UP func() bool = func() bool {
return true
}
// EXTRAS show more informations in status
EXTRAS interface{} = nil
)
// Status API response
type Status struct {
Version string `json:"version"`
Up bool `json:"up"`
Extras interface{} `json:"extras,omitempty"`
}
// Register status module
// @Summary Show Status of current API
// @Description Show version and status
// @Tags status
// @Produce json
// @Success 200 {object} Status
// @Failure 400 {object} web.HTTPError
// @Failure 404 {object} web.HTTPError
// @Router /api/status [get]
func Register(r *gin.Engine, ws *web.Service) {
r.GET("/api/status", func(c *gin.Context) {
status := &Status{
Version: VERSION,
Up: UP(),
Extras: EXTRAS,
}
if !status.Up {
c.JSON(http.StatusInternalServerError, status)
return
}
c.JSON(http.StatusOK, status)
})
}